Results 1 to 8 of 8

Thread: Relation of PascalScript to Java?

  1. #1
    Join Date
    Mar 2013
    Location
    Shaolin
    Posts
    863
    Mentioned
    24 Post(s)
    Quoted
    519 Post(s)

    Default Relation of PascalScript to Java?

    So if I'm grasping any of this even remotely, what are the similarities between Java and PascalScript (what Simba uses)?

    So { and } and like begin and end?
    Methods are like procedures?

    What else about pascal could help me with learning Java? I'm reading the Dummies book and just have a little trouble sometimes. A concrete example between the 2 languages would be sweet.

    ~Wu
    You have permission to steal anything I've ever made...

  2. #2
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    begin is like { and end is like } ofc
    records are similar to objects (but they are totally different things)
    public void blah blah blah() {} is like a procedure (returns nothing)
    public int blahblah() {} is like a function
    'return' is like exit
    (return true is like result := true and exit combined, or exit(true) in lape)


    Other than that.. not many like features that 'stand out', Java is OOP you won't find many similarities


    2 solid examples (used lape but w-e)


    Simba Code:
    type
      Box = record
        X1, Y1, X2, Y2:integer;
      end;


    function Box.new(XX1, YY1, XX2, YY2:integer):Box;
    begin
      result.X1 := XX1;
      result.Y1 := YY1;
      result.X2 := XX2;
      result.Y2 := YY2;
    end;

    function Box.width:integer;
    begin
      result := (self.X2 - self.X1);
    end;

    function Box.height:integer;
    begin
      result := (self.Y2 - self.Y1);
    end;

    var
      someBox:Box;

    begin
      someBox := someBox.new(5, 5, 10, 10);
      writeln(somebox.width());
      writeln(somebox.height());
    end.


    Java:

    main.java


    java Code:
    package main;

    import main.Box;

    public class Main {
       
        public static void main(String[] args) {
            Box someBox = new Box(5, 5, 10, 10);
            System.out.println(someBox.width());
            System.out.println(someBox.height());
        }

    }

    Box.java:

    java Code:
    package main;

    public class Box {
       
        public int x1;
        public int y1;
        public int x2;
        public int y2;
       
        public Box(int x1, int y1, int x2, int y2) {
            this.x1 = x1;
            this.x2 = x2;
            this.y1 = y1;
            this.y2 = y2;
        }
       
        public int width() {
            return (this.x2 - this.x1);
        }
       
        public int height() {
            return (this.y2 - this.y1);
        }

    }

  3. #3
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Don't forget function pointers:

    Java Code:
    package lambdas;

    import java.util.*;
    import java.util.function.*;

    /**
     *
     * @author Brandon
     */

    public class Lambdas {

        /**
         * @param args the command line arguments
         */

        public static void main(String[] args) {
            Thread t = new Thread(() -> {
                System.out.println("Thread Proc");
            });

            t.start();
            sleep(100);

            Thread t2 = new Thread(() -> System.out.println("Thread Proc 2"));
            t2.start();
            sleep(100);

            Thread t3 = new Thread(Lambdas::somefunc);
            t3.start();
            sleep(100);

            Thread t4 = new Thread((new Lambdas())::somefunc2);
            t4.start();
            sleep(100);

            List<Integer> list = Arrays.asList(10, 3, 9, 6, 4, 1, 7, 8, 5, 2);
            sort(list, (Integer a, Integer b) -> a < b);
            list.forEach(System.out::println);

            System.out.println();
            System.out.println();
           
            list = Arrays.asList(10, 3, 9, 6, 4, 1, 7, 8, 5, 2);
            list.sort((a, b) -> a < b ? a.equals(b) ? 0 : -1 : 1);
            list.forEach(System.out::println);
        }

        static void somefunc() {
            System.out.println("Some func");
        }

        void somefunc2() {
            System.out.println("Some func 2");
        }

        static <T> void sort(List<T> list, BiFunction<T, T, Boolean> func) {
            for (int i = 0; i < list.size() - 1; ++i) {
                for (int j = 0; j < list.size() - i - 1; ++j) {
                    T a = list.get(j);
                    T b = list.get(j + 1);
                   
                    if (func.apply(b, a)) {
                        T temp = a;
                        list.set(j, b);
                        list.set(j + 1, temp);
                    }
                }
            }
        }

        static void sleep(long millis) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
        }
    }


    In PS, the equivalent of any of the above would be:

    Simba Code:
    procedure somefunc();
    begin
      writeln('Some func');
    end;

    procedure somefunc2();
    begin
      writeln('Some func 2');
    end;

    procedure sort(var list: array of Integer; func: Function(A, B: Integer): Boolean);
    var
      I, J, L: Integer;
      a, b, temp: Integer;
    begin
      L := Length(list);

      for I := 0 To L - 1 do
      begin
        for J := 0 to L - I - 2 do
        begin
          a := list[j];
          b := list[j + 1];

          if (func(b, a)) then
          begin
            temp := a;
            list[j] := b;
            list[j + 1] := temp;
          end;
        end;
      end;
    end;

    procedure SleepEx(millis: LongInt);
    begin
      try
        sleep(millis);
      except
      end;
    end;

    function compare(a, b: Integer): boolean;
    begin
      Result := a < b;
    end;


    var
      list: array of Integer;
    begin
      list := [10, 3, 9, 6, 4, 1, 7, 8, 5, 2];
      Sort(list, @compare);

      writeln(list);
    end.
    Last edited by Brandon; 03-21-2014 at 02:52 AM.
    I am Ggzz..
    Hackintosher

  4. #4
    Join Date
    Nov 2006
    Posts
    2,369
    Mentioned
    4 Post(s)
    Quoted
    78 Post(s)

    Default

    Most difficult is probably to understand how to do object oriented programming.

    Object is a bit like record in pascal but objects can also contain methods. A method has access to all the variables and methods withing the same object unlike in pascalscript. For example you could have object Box that has variables width and height and a method called getArea() that returns width*height. In pascalscript you should pass width and height as parameters to the function even if the function was part of a record that contains width and height.
    Quote Originally Posted by DeSnob View Post
    ETA's don't exist in SRL like they did in other communities. Want a faster update? Help out with updating, otherwise just gotta wait it out.

  5. #5
    Join Date
    Feb 2013
    Location
    Narnia
    Posts
    615
    Mentioned
    8 Post(s)
    Quoted
    252 Post(s)

    Default

    its kind of a long vid and ive made myself about half way through it going back when im bored, pretty basic functions of java such as declaring variables, and for loops. thats all ive gotten to so far in it, im sure theres more. its a great tut though and u might like it

    http://www.youtube.com/watch?v=3u1fu6f8Hto

    View my OSR Script Repository!


    Botted to max
    Guides: How to Report Bugs to the Scripter
    ~~~~ Moved to Java. Currently Lurking ~~~~

  6. #6
    Join Date
    Dec 2010
    Posts
    483
    Mentioned
    30 Post(s)
    Quoted
    328 Post(s)

    Default

    What you need to do is not compare the two. Like you, I started out scripting in pascal (actually closer to Delphi by the way) wayyy back with SCAR1.3 I believe it was. Later I went on to create java based bots and write tutorials on the such in many of the java-based communities back then.

    Java is a whole different ball game. First read up on OOP (Object Oriented Programming). Java is forced OOP, whereas Pascal doesn't even support it (shh, yes I know Delphi does but its crap lets me honest).

    Your best friend and resource:
    http://docs.oracle.com/javase/tutorial/

  7. #7
    Join Date
    Sep 2012
    Location
    Netherlands
    Posts
    2,752
    Mentioned
    193 Post(s)
    Quoted
    1468 Post(s)

    Default

    Quote Originally Posted by the bank View Post
    What you need to do is not compare the two. Like you, I started out scripting in pascal (actually closer to Delphi by the way) wayyy back with SCAR1.3 I believe it was. Later I went on to create java based bots and write tutorials on the such in many of the java-based communities back then.

    Java is a whole different ball game. First read up on OOP (Object Oriented Programming). Java is forced OOP, whereas Pascal doesn't even support it (shh, yes I know Delphi does but its crap lets me honest).

    Your best friend and resource:
    http://docs.oracle.com/javase/tutorial/
    look at the post date

  8. #8
    Join Date
    Dec 2010
    Posts
    483
    Mentioned
    30 Post(s)
    Quoted
    328 Post(s)

    Default

    Quote Originally Posted by hoodz View Post
    look at the post date
    Shit my bad man. Not really grave-digging if its on the front page though is it? Not my fault this part of the forum is dead. I love Java

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •