Results 1 to 7 of 7

Thread: Yummy Const

  1. #1
    Join Date
    Nov 2008
    Posts
    117
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default Yummy Const

    Quick newbish question...

    Can Const be placed anywhere aside from the top of the script, like in functions and such? (Yes yes, I know you use them as parameters for functions, but that's not quite what Im looking for).


    Like, is there anyway to make the following work, while keeping the const local to the procedure 'a':

    Code:
    program New;
    procedure a;
    const
      aa = 1112;
    begin
      writeln(inttostr(aa));
    end;
    
    begin
          a;
    end.

  2. #2
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    I think Delphi supports that . But not scar.

    Your best bet would be to have a const at the beginning of a script and then pass it to a variable. Or just cut the middle-man out and have a variable:

    SCAR Code:
    program New;
    procedure a;
    Var aa : Integer;
    begin
      aa := 1112;
      writeln(inttostr(aa));
    end;

    begin
          a;
    end.


  3. #3
    Join Date
    Jan 2007
    Posts
    834
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Can you explain a bit more? Are you trying to say if you can use it like a local variable? If so, no. It will come up as an error.

    ninjerd

  4. #4
    Join Date
    May 2008
    Posts
    1,345
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I know they can be placed anywhere outside a procedure, but I don't know about that.

    ~Sand

  5. #5
    Join Date
    Nov 2008
    Posts
    117
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    Ah, I see. Thank you very much everyone.

    I'm much more used to standard programming languages myself, which is why I was a bit baffled that I couldn't make a local constant. Guess I have to stick to global constants and local variables then.

    Thanks again!

  6. #6
    Join Date
    Sep 2007
    Location
    Michigan
    Posts
    3,862
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    You can just place the const above the function since as stated const's inside a function isn't supported in scar.
    (Scripts outdated until I update for new SRL changes)
    AK Smelter & Crafter [SRL-Stats] - Fast Fighter [TUT] [SRL-Stats]
    If you PM me with a stupid question or one listed in FAQ I will NOT respond. -Narcle
    Summer = me busy, won't be around much.

  7. #7
    Join Date
    Nov 2008
    Posts
    117
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    Hmm, yes that would preserve the 'global' aspect of the const while giving it a bit more aesthetic appeal, placement wise. Thanks for the dirty work-around

    PS- Lelouch is awesome

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
  •