Results 1 to 10 of 10

Thread: Case Problems

  1. #1
    Join Date
    Apr 2007
    Posts
    379
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Case Problems

    I am working on my script(still) and I have SRL 4 Beta.

    My problem is I get a Variable Expected Problem, Here is what I have

    SCAR Code:
    Const
     OakColor1 = 2186836; OakColor2 = 3116158; OakColor3 = 1730648;

     Procedure RandomOakColor;
     Begin
      Status('Picking Random Oak Color from Consts.');
       Case Random(3) of
        0: OakColor1;
        1: OakColor2
        2: OakColor3
      end;
    And in my script I want to use it like this

    SCAR Code:
    Procedure OakChop; //Chops Oaks, Checks for ent, Checks Axe, Full Inv Check,
     Begin
     Status('Chopping Oaks');
     SendArrowWait(1, 900+Random(500));
      If(FindColorSpiralTolerance(tx, ty, RandomOakColor, 1, 1, 514, 336, 4))Then
       Begin
        MMouse(tx, ty, 15, 15);
         If(IsUpTextMulti('Oak', 'ak', 'oak')) Then
          Begin

    That is not the full part of that procedure but the part I need help on is up there.

  2. #2
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Do something like this:

    SCAR Code:
    Const
     OakColor1 = 2186836; OakColor2 = 3116158; OakColor3 = 1730648;
     
    function RandomOakColor: integer;
    Begin
      Status('Picking Random Oak Color from Consts.');
      Case Random(3) of
        0: Result := OakColor1;
        1: Result := OakColor2;
        2: Result := OakColor3;
      end;
    end;

    Then you should be able to do what you want to do in your other procedure.

    EDIT: I should also mention that you need a function to return a value. You can't use a procedure. Thats why I've replaced 'Procedure' with 'Function'.

  3. #3
    Join Date
    Jul 2007
    Location
    UK
    Posts
    307
    Mentioned
    0 Post(s)
    Quoted
    5 Post(s)

    Default

    You always put a end; when your done with a case (Cases have there own ends (end; ) )

  4. #4
    Join Date
    Apr 2007
    Posts
    379
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    @Cathering, I know I had put this together really quick, I knew that error has nothing to do with ends, so I just I guess forgot about it.

  5. #5
    Join Date
    May 2007
    Location
    baltimore, md
    Posts
    836
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    why pick a random oak color why not use all of them with an integer array.

  6. #6
    Join Date
    Jul 2007
    Location
    UK
    Posts
    307
    Mentioned
    0 Post(s)
    Quoted
    5 Post(s)

    Default

    EDITED : Sorry Trails Ive been really ignoreant these past few days.

  7. #7
    Join Date
    Apr 2007
    Posts
    379
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Let me clarrify, In my script I had the ends neccissary, even then the error was caused, i had put it into a different scar tab for easier copying and pasting, I just left out an end on accident.

    It did not work before if I had 2 ends or just 1 so I had asked and it was a simple fix from Zepher.

    And I don't know exactly how to completely use arrays, and I generally don't put things I don't know into my script.

  8. #8
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    Cases just dont suddenly stop working,
    The error DOSE have something to do with ends; cases have there own ends;...
    How many doses does your case have left?

    And no. The "end;" had nothing to do with variable excepted error.

    Variable expected comes, when you "start using a variable" but then dont use. I cant explain, but lets say

    "Result;" That just simply "says" the variable, which is impossible.

    When you start doing something with a variable, it has to be end.
    Like, "Result := Result + 1;"

  9. #9
    Join Date
    Jan 2007
    Posts
    117
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by n3ss3s View Post
    How many doses does your case have left?

    And no. The "end;" had nothing to do with variable excepted error.

    Variable expected comes, when you "start using a variable" but then dont use. I cant explain, but lets say

    "Result;" That just simply "says" the variable, which is impossible.

    When you start doing something with a variable, it has to be end.
    Like, "Result := Result + 1;"
    basically, where the script wanted/"expected" a variable, u wernt giving it 1, because u were giving randomoakcolor which was a procedure, not a variable or a function (which effectively acts as a variable by returning a variable). but thanks to zephers its all sorted
    No Signature Assigned.

  10. #10
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    I'm not sure if this is what n3ss3s is trying to say but the reason for the variable expected error was because you haven't told the script to do anything with the 3 colours.

    SCAR Code:
    Case Random(3) of
        0: OakColor1;
        1: OakColor2
        2: OakColor3
      end;

    You've just gone and went 'case Random(3) of' but haven't told the script to do anything. SCAR is expecting you to store the colour in a variable but you haven't done that... so theres the error.

    Anyway glad to help .

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Case help
    By Aser in forum OSR Help
    Replies: 3
    Last Post: 11-22-2008, 05:21 AM
  2. case ... of problems
    By Dusk412 in forum OSR Help
    Replies: 6
    Last Post: 05-20-2008, 03:08 AM
  3. Case..Of Help
    By Drew_Dawg in forum OSR Help
    Replies: 7
    Last Post: 02-02-2008, 11:47 PM
  4. In case if you got problems with connection
    By Negaal in forum Research & Development Lounge
    Replies: 4
    Last Post: 01-29-2008, 10:10 PM
  5. Case - Else
    By stylen in forum OSR Help
    Replies: 0
    Last Post: 05-30-2007, 11:54 PM

Posting Permissions

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