Results 1 to 13 of 13

Thread: Help with my script?

  1. #1
    Join Date
    Feb 2009
    Location
    Irvine, CA
    Posts
    2,873
    Mentioned
    8 Post(s)
    Quoted
    138 Post(s)

    Default Help with my script?

    hey guys im writing an AFK training script which will hopefully develop into a full fledged SoS script.

    here is what i have so far

    Code:
    program AFK;
    
    {.include srl/srl/misc/smart.scar}
    {.include srl/srl.scar}
    
    function eat:boolean;
     var
      Temp:string;
    begin
     if GetMMLevels('hp',temp) <> -1 then begin if temp = 'yellow' then EatFood;
    end;
    
    function EatFood:boolean;
    begin
    end;
    
    
    begin;
     clear debug
     eat
     EatFood
    end.
    i get this error when i run it

    Code:
    Line 10: [Error] (19894:68): Unknown identifier 'EatFood' in script
    when i clearly have a simple EatFood function (with nothing in it :P)

    halp mah?

    EDIT: also i need help on how to make functions return a boolean ^_^ help appreciated

  2. #2
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    SCAR Code:
    program AFK;

    {.include srl/srl/misc/smart.scar}
    {.include srl/srl.scar}

    function eat:boolean;
     var
      Temp:string;
    begin
     if GetMMLevels('hp',temp) <> -1 then begin if temp = 'yellow' then EatFood; // <-- reason for error.
    end;

    function EatFood:boolean;
    begin
    end;


    begin //<-- Begin doesn't get a semicolon after it ;)
     cleardebug; //<-- no spaces in names.
     eat;
     EatFood;
    end.

    You can't use a function before you declare what it is

    either swap the order around, or learn forwards

  3. #3
    Join Date
    Feb 2009
    Location
    Hungary (GMT + 1)
    Posts
    1,774
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    The order of the lines really count.
    And you use the EatFood function before you declare it. Solution: place the EatFood function before the eat function.

    EDIT: lol I have been ninjad

  4. #4
    Join Date
    Feb 2009
    Location
    Irvine, CA
    Posts
    2,873
    Mentioned
    8 Post(s)
    Quoted
    138 Post(s)

    Default

    ok now i got:

    Code:
    program AFK;
    {.include srl/srl/misc/smart.scar}
    {.include srl/srl.scar}
    
    function EatFood:boolean;
    begin
    end;
    
    function eat:boolean;
     var
      Temp:string;
      Result:Boolean;
    begin
     if GetMMLevels('hp',temp) <> -1 then begin if temp = 'yellow' then EatFood;
     if result = true then EatFood;
    end;
    
    begin;
     cleardebug;
     eat;
     EatFood;
    end.
    and my new error is

    Failed when compiling
    Line 5: [Hint] (19889:10): Variable 'Result' never used in script
    Line 12: [Error] (19896:1): Duplicate identifier 'Result' in script

  5. #5
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    SCAR Code:
    program AFK;
    {.include srl/srl/misc/smart.scar}
    {.include srl/srl.scar}

    function EatFood:boolean;
    begin
    end;

    function eat:boolean;
     var
      Temp:string;
      {Result:Boolean;} //<-- not necessary, this function returns a Boolean.
    begin
     if GetMMLevels('hp',temp) <> -1 then begin if temp = 'yellow' then EatFood;
     if result = true then EatFood;
    end;

    begin;
     cleardebug;
     eat;
     EatFood;
    end.

    Also, in you 'eat' function, you never set the Result to True for anything so it will always return False as that is the default for all booleans.

  6. #6
    Join Date
    Feb 2009
    Location
    Irvine, CA
    Posts
    2,873
    Mentioned
    8 Post(s)
    Quoted
    138 Post(s)

    Default

    Quote Originally Posted by NCDS View Post
    Also, in you 'eat' function, you never set the Result to True for anything so it will always return False as that is the default for all booleans.
    Quote Originally Posted by TomTuff View Post
    EDIT: also i need help on how to make functions return a boolean ^_^ help appreciated

    i already said i needed help w/ that

    edit: ncds, i added u on msn, i got to go to the pool right now :]
    Last edited by TomTuff; 08-06-2009 at 06:09 AM.

  7. #7
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    Oh >.< sorry, I didn't see that.

    Well as long as your function is set to return a Boolean (: Boolean; is after the function name)
    then all you have to put is Result := True; and that would return the function as True.

    Example:
    SCAR Code:
    function BoolHelp: Boolean;
    begin
      if TomTuffUnderstands then
      Result := True;
    end;

    Get it?
    Last edited by NCDS; 08-06-2009 at 06:12 AM.

  8. #8
    Join Date
    Feb 2009
    Location
    Irvine, CA
    Posts
    2,873
    Mentioned
    8 Post(s)
    Quoted
    138 Post(s)

    Default

    hm so say i want it to return as true when temp is orange or red, do i put
    if temp = 'yellow' or 'orange' or 'red' then result := true else result := false;

    ?

  9. #9
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    SCAR Code:
    if temp = 'orange' or temp = 'red' then
      Result := True


    What you sent me on MSN:
    SCAR Code:
    function eat:boolean;
     var
      Temp tring;
    begin
     if GetMMLevels('hp',temp) <> -1 then begin if result = true then EatFood;
     if temp = 'orange' or temp = 'red' then Result := True;
    end;
    You check to see if the result is true before you ever set it to true

    Fixed:
    SCAR Code:
    function eat: boolean;
     var
      Temp: string;
    begin
      if GetMMLevels('hp',temp) <> -1 then
        if temp = 'orange' or temp = 'red' then
        begin
          Result := True;
          EatFood;
        end;
    end;
    Last edited by NCDS; 08-06-2009 at 06:22 AM.

  10. #10
    Join Date
    Feb 2009
    Location
    Irvine, CA
    Posts
    2,873
    Mentioned
    8 Post(s)
    Quoted
    138 Post(s)

    Default

    program AFK;
    {.include srl/srl/misc/smart.scar}
    {.include srl/srl.scar}

    function EatFood:boolean;
    begin
    writeln('it worked')
    end;

    function eat:boolean;
    var
    Temp:string;
    begin
    if GetMMLevels('hp',temp) <> -1 then
    if temp = 'orange' or temp = 'red' then;
    begin
    result := True;
    EatFood;
    end;
    end;

    begin
    cleardebug;
    eat;
    EatFood;
    end.


    that's what i have now.



    now i get this error:

    Failed when compiling
    Line 5: [Hint] (19889:10): Variable 'Result' never used in script
    Line 15: [Error] (19899:28): Type mismatch in script

  11. #11
    Join Date
    Dec 2008
    Posts
    209
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    EatFood is declared as a function, thus requires a value to be returned (Result := .. (it's not being used - that's what SCAR was hinting)) if you don't want to return a value then change it from a function to a procedure:
    change
    PHP Code:
    function EatFoodboolean 
    to
    PHP Code:
    procedure EatFood
    The second error is that you need to enclose logicals inside parentheses, like so:
    PHP Code:
    if (a) or (bthen 
    ..

    Hope I helped
    Last edited by Craig`; 08-06-2009 at 07:11 AM.

  12. #12
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    here, i fixed it up, it now works(your script says so )

    SCAR Code:
    program AFK;
    {.include srl/srl/misc/smart.scar}
    {.include srl/srl.scar}

    function EatFood:boolean;
    begin
      writeln('it worked')
    end;

    function eat:boolean;
    var
      Temp:string;
    begin
      if GetMMLevels('hp',temp) <> -1 then
      if (temp = 'orange') or (temp = 'red') then
      begin
        result := True;
        EatFood;
      end;
    end;

    begin
      cleardebug;
      eat;
      EatFood;
    end.

    you also had a semicolon at the end of a then, thats a no-no! haha
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  13. #13
    Join Date
    Feb 2009
    Location
    Irvine, CA
    Posts
    2,873
    Mentioned
    8 Post(s)
    Quoted
    138 Post(s)

    Default

    Quote Originally Posted by Awkwardsaw View Post
    here, i fixed it up, it now works(your script says so )

    Code:
    program AFK;
    {.include srl/srl/misc/smart.scar}
    {.include srl/srl.scar}

    function EatFood:boolean;
    begin
    writeln('it worked')
    end;

    function eat:boolean;
    var
    Temp:string;
    begin
    if GetMMLevels('hp',temp) <> -1 then
    if (temp = 'orange') or (temp = 'red') then
    begin
    result := True;
    EatFood;
    end;
    end;

    begin
    cleardebug;
    eat;
    EatFood;
    end.


    you also had a semicolon at the end of a then, thats a no-no! haha
    +r-r-r-r-rep!

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
  •