Results 1 to 4 of 4

Thread: Uninitialized variables

  1. #1
    Join Date
    Mar 2008
    Posts
    38
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Uninitialized variables

    Can someone help clear things up for me here. I talked with Freedy about SCAR. He said he is currently using Delphi 7 with a script engine and creating a thread to launch the script in. Now I know from experience and Freedy agreed that variables do not get magically initialized to any particular value.
    As you can see from my "Chicken" status that I am just a noob at SRL so I am assuming there is something I don't know about here but a lot of the code I have been looking at in the SRL library uses variables that are never initialized.
    I copied and pasted some code below from the logout method.
    You will notice that the local variable "c" is never initialized, so it could have a value of 83458736 as far as we know. Given that, you can see how the logic would not work i teajut happened to be something other than 0. This is just one of many examples I have run accross. I wrote a test program in delphi and attached a screen capture of the program window running in front of the source for the button click to demonstrate my point. I don't want to sound as if I am complaining because I am not. But I would like for either someone to explain to me how variables get initialized or we should begin going through all the existing code to fix these bugs. By the way these would be random because based on what other programs have run before you may get an unused area of memory or not so the values are completely unpredictable. I know some languages do initialize memory for you so I am assuming the developers are used to the other languages.

    --------------code snipit--------------
    function Logout: Boolean;
    var
    c, i: Integer;
    begin
    Result := (not (LoggedIn));
    if Result = True then
    Exit;
    if GameTab(14) = False then
    Exit;
    Wait(200 + Random(100));
    while (LoggedIn) or (c < 10) do
    begin
    --------------------------------------

  2. #2
    Join Date
    Jul 2007
    Posts
    1,431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I rly can't understand what are you trying to say. But you said something like non-inztalised var may have value like 45986549, right?

    As far I know, not true, when you haven't filled it with anything, it should be empty - 0/false/empty string.
    [CENTER][SIZE="4"]Inactive[/SIZE]I forgot my password[/CENTER]

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

    Default

    In SCAR, the values are "0" by default, a string is '' by default, boolean is False by default and an integer is 0 by default.

    Run this:

    SCAR Code:
    Program New;

    Var
       I: Integer;
       E: Extended;
       B: Boolean;
       S: String;
       
       A: Array of Variant;
       
    Begin
      Writeln(IntToStr(i));
      Writeln(FloatToStr(e));
      Writeln(BoolToStr(B));
      Writeln(S);
      Writeln(IntToStr(Length(A)));
    End.

  4. #4
    Join Date
    Mar 2008
    Posts
    38
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    N3ss3s, that appears to be true. In fact after thinking about it, the scripting engine I use with Delphi ( FastScript ) also initializes the memory even though Delphi itsself does not. I will try your test script in different situations but at this point at least I feel better about it. Now if I can just stop myself from writing extra lines of code to initialize my vars I will be alright. Its a good habit albit not necessary for scripting.

    Negaal, .... nevermind ... at least you avatar pic is hot. :-)

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Uninitialized variables
    By NosePicker in forum OSR Help
    Replies: 2
    Last Post: 03-20-2008, 07:34 PM
  2. Variables
    By Jackrawl in forum OSR Help
    Replies: 4
    Last Post: 12-04-2007, 04:30 PM
  3. Variables..
    By doritoz in forum OSR Help
    Replies: 19
    Last Post: 09-03-2007, 03:10 AM

Posting Permissions

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