Results 1 to 7 of 7

Thread: Findobj function.

  1. #1
    Join Date
    Sep 2006
    Posts
    457
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Findobj function.

    So i want to make a findobj function. Is there anyway to make like a local constant in the procedure?
    so like

    SCAR Code:
    Procedure FindTree;
    const
    TreeColor = 0;

    begin...rest of findobj.

    SCAR Code:
    Procedure FindTree;
     If(FindObj3(x, y, 'hop', 5268081, 10)) Then
      WriteLn('found tree');
     end;
     
    Begin
     SetupSRL;
     FindTree;
    end.
    Finished my curser ---> it's in mage section.

  2. #2
    Join Date
    Apr 2007
    Location
    Texas
    Posts
    1,668
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    you normally do not declare constants inside of a function. Any values that you want to be constants, shold instead just be vairable passed too the function itself, (unless they will never change, in which a constant would be nothing more than a name, and you should just manualy type in the data instead)

    look,
    SCAR Code:
    function FindTree(treeColor: Integer;): Boolean;
    begin
      If(FindObj3(x, y, 'hop', treeColor, 10)) Then
        WriteLn('found tree');
    end;
    and you would use it like
    SCAR Code:
    findTree(5268081);
    or if you HAVE to have constants, declare a constant in your main script like you normally would, and then pass it to it.

    the reason for this is that functions are suposed to be flexible, and very usable, in almost any circumstance. yu never want to have to change the code of a function once you have written it.

    take srls functions, how many times have you had to modify the includes to fit your script? never.

    your functions shold be the same, allow as much flexablility as possible.

    chaning it to a constant inside the function would prevent it from being used with any other tree color, or even a tree autocoloring technique.
    [IMG]http://farm3.static.flickr.com/2120/2052732965_348f3629d0_o.jpg[/IMG]

  3. #3
    Join Date
    Jul 2007
    Location
    Right now? Chair.
    Posts
    8,488
    Mentioned
    3 Post(s)
    Quoted
    12 Post(s)

    Default

    you can make a local variable and then assign a value to it.

    I & I know Zion. It is in the spirit, body and mind of every one of us
    RMouse(obj: TMSIObject): boolean;

  4. #4
    Join Date
    Sep 2006
    Posts
    457
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    wow thanks greg that made me understand so much better
    Finished my curser ---> it's in mage section.

  5. #5
    Join Date
    Apr 2007
    Location
    Texas
    Posts
    1,668
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    glad to help out. keep in mind that you can pass a function as many diferent vaiables as you want, and they can be of diferent types as well.

    you can also have the function reture a value (only one though)

    so you can use a function to calculate a certain number for you, or return other values, etc.

    SCAR Code:
    function FindTree(treeColor: Integer;): Boolean;
    var succes: Boolean;
    begin
      succes:=false;
      If(FindObj3(x, y, 'hop', treeColor, 10)) Then
      begin
        WriteLn('found tree');
        succes:=true;
      end;
    Result:=succes;
    end;
    and result would be the return value.
    then you can do
    SCAR Code:
    if FindTree(566031) then
    begin
      writeln('celebration');
    end;
    [/scar]
    [IMG]http://farm3.static.flickr.com/2120/2052732965_348f3629d0_o.jpg[/IMG]

  6. #6
    Join Date
    Sep 2006
    Posts
    457
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    thanks that helps, So i just dont want to have to put the stupid const at the top of the set up. I want to have like 3 colors for a tree and have a 5 tolerance. So could i make like a case of colors. I know it's confusing but...
    Finished my curser ---> it's in mage section.

  7. #7
    Join Date
    Apr 2007
    Location
    Texas
    Posts
    1,668
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    ill let you handle that one bud

    you dont want me doing all the fun stuff now do you?

    gl
    [IMG]http://farm3.static.flickr.com/2120/2052732965_348f3629d0_o.jpg[/IMG]

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. FindObj help
    By daddyproboot in forum OSR Help
    Replies: 6
    Last Post: 08-17-2007, 03:48 PM
  2. FindObj help
    By Xirx in forum OSR Help
    Replies: 7
    Last Post: 06-12-2007, 09:38 PM
  3. findobj?
    By omgh4x0rz in forum OSR Help
    Replies: 15
    Last Post: 02-10-2007, 12:34 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
  •