Results 1 to 5 of 5

Thread: The problem with arrays...

  1. #1
    Private
    Join Date
    Aug 2012
    Posts
    78
    Thanks
    20
    Thanked 10 Times in 5 Posts

    The problem with arrays...

    Hey all

    I wrote a script that handles the array. The script only works on the last table, in my case I have 3 tables, and only the last one works as it should

    Tables:

    Code:
    level.weapons = [];
    level.weapons[0] = spawnStruct();
    level.weapons[0].weapon = "thompson_mp";
    level.weapons[0].numberimage = "1";
    
    level.weapons[1] = spawnStruct();
    level.weapons[1].weapon = "kar98k_mp";
    level.weapons[1].numberimage = "2";
    
    level.weapons[2] = spawnStruct();
    level.weapons[2].weapon = "m1carbine_mp";
    level.weapons[2].numberimage = "3";
    Script:
    Code:
                if(response == "buttons")
                {
                    for(i = 0; i < level.weapons.size; i++)
                    {
                        guid = self getGuid();
                        self thread files\_propertiesguid::load(guid); // Load self.oldweapon
                        
                        if(self.oldweapon == level.weapons[i].weapon)
                        {
                            self setClientCvar(weaponButton, "3");
                            self setClientCvar(weaponImage, level.weapons[i].numberimage);
                        }
                        else
                        {
                            self setClientCvar(weaponButton, "2");
                            self setClientCvar(weaponImage, "0");
                        }
                    }
                }
    Last table, which is the third "m1carbine_mp" is working correctly, but the first two spoil the script ...
    The first two arrays bad work on the script, if they read the script uses the "if" and "else" at the same time
    Please Help me..

  2. #2
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,010
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    I dont know exactly what you want to do, but maybe this could help:

    Code:
                if(response == "buttons")
                {
                    for(i = 0; i < level.weapons.size; i++)
                    {
                        guid = self getGuid();
                        self thread files\_propertiesguid::load(guid); // Load self.oldweapon
                        
                        if(self.oldweapon == level.weapons[i].weapon)
                        {
                            self setClientCvar(weaponButton, i + 1); // maybe convert this to string, e.g. ""+(i+1)
                            self setClientCvar(weaponImage, level.weapons[i].numberimage);
                            break;
                        }
                    }
                }
    timescale 0.01

  3. The Following User Says Thank You to kung foo man For This Useful Post:

    Moczulak (4th February 2013)

  4. #3
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Converting to string isnt needed
    I would advise you to move the getguid() and that other thread out of the loop.

    Also, if timing is critical, DO NOT THREAD that function. Remove thread-word.

  5. The Following 2 Users Say Thank You to IzNoGoD For This Useful Post:

    kung foo man (3rd February 2013),Moczulak (4th February 2013)

  6. #4
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,010
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    Quote Originally Posted by IzNoGoD View Post
    Also, if timing is critical, DO NOT THREAD that function. Remove thread-word.
    Just to express that in code.

    From:
    Code:
    self thread files\_propertiesguid::load(guid); // Load self.oldweapon
    To:
    Code:
    self files\_propertiesguid::load(guid); // Load self.oldweapon
    timescale 0.01

  7. The Following 2 Users Say Thank You to kung foo man For This Useful Post:

    IzNoGoD (4th February 2013),Moczulak (4th February 2013)

  8. #5
    Private
    Join Date
    Aug 2012
    Posts
    78
    Thanks
    20
    Thanked 10 Times in 5 Posts
    Thanks kung foo man and IzNoGoD

Posting Permissions

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