SA-MP Forums Archive
How to change a variable? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How to change a variable? (/showthread.php?tid=360488)



How to change a variable? - Rabbayazza - 17.07.2012

pawn Код:
new GateOpenStatus;
new DoorStatus;

// ^ Top //

    GateOpenStatus = 0;
    DoorStatus = 0;

// ^^ OnGameModeInit //

    if(!strcmp(cmdtext, "/", true))
        {
            if(GateOpenStatus == 0)
            if(IsPlayerInRangeOfPoint(playerid, 10, 1410.19995117, -1650.09997559, 13.80000019))
        {
                MoveObject(GateOpen, 1410.09997559, -1650.09997559, 10.80000019, 3);
                SendClientMessage(playerid, 0xEF994300, "You have opened the gate.");
        }
                    else if(GateOpenStatus == 1)
        {
                MoveObject(GateOpen, 1410.19995117, -1650.09997559, 13.80000019, 3);
                SendClientMessage(playerid, 0xEF994300, "You have closed the gate.");
        }
            if(DoorStatus == 0)
            if(IsPlayerInRangeOfPoint(playerid, 10, 955.70001221,-50.70000076,1002.00000000))
        {
                MoveObject(Door, 955.70001221,-50.59999847,998.20001221, 3);
        }
                else if(DoorStatus == 1)
        {
                MoveObject(Door, 955.70001221,-50.70000076,1002.00000000, 3);
        }
            return 1;
        }
// cmd //

How do I make the GateOpenStatus and DoorStatus change to 1 after opening them?


Re: How to change a variable? - Ranama - 17.07.2012

pawn Код:
/*
new GateOpenStatus;
//You don't have to do this, you can give them the value of 0 when you declare them like i did under here
new DoorStatus;
*/


new GateOpenStatus = 0;
new DoorStatus = 0;

// ^^ OnGameModeInit //

    if(!strcmp(cmdtext, "/", true))//you need to put the command name here ^^
        {
            if(GateOpenStatus == 0)
            if(IsPlayerInRangeOfPoint(playerid, 10, 1410.19995117, -1650.09997559, 13.80000019))
        {
                MoveObject(GateOpen, 1410.09997559, -1650.09997559, 10.80000019, 3);
                SendClientMessage(playerid, 0xEF994300, "You have opened the gate.");
                                            GateOpenStatus = 1;
        }
                    else if(GateOpenStatus == 1)
        {
                MoveObject(GateOpen, 1410.19995117, -1650.09997559, 13.80000019, 3);
                SendClientMessage(playerid, 0xEF994300, "You have closed the gate.");
                      GateOpenStatus = 0;
        }
            if(DoorStatus == 0)
            if(IsPlayerInRangeOfPoint(playerid, 10, 955.70001221,-50.70000076,1002.00000000))
        {
                MoveObject(Door, 955.70001221,-50.59999847,998.20001221, 3);
                              DoorStatus = 1;
        }
                else if(DoorStatus == 1)
        {
                MoveObject(Door, 955.70001221,-50.70000076,1002.00000000, 3);
                              DoorStatus = 0;
        }
            return 1;
        }
// cmd //
When you use a variable and = it means that you are giving it a new value, as i did in the script up there. While you use == if you want to know if the variable is equal to something, and === if it's exactly equal to something ( don't know if pawno have === but I know it's used in many other programming languages)
hope i helped


Re: How to change a variable? - Rabbayazza - 18.07.2012

Didn't work, when I do "/" the second time nothing happens.


Re: How to change a variable? - ViniBorn - 18.07.2012

Try this

pawn Код:
/*
new GateOpenStatus;
//You don't have to do this, you can give them the value of 0 when you declare them like i did under here
new DoorStatus;
*/


new bool:GateOpenStatus;
new bool:DoorStatus;

// ^^ OnGameModeInit //

if(!strcmp(cmdtext, "/", true))//you need to put the command name here ^^
{
    if(IsPlayerInRangeOfPoint(playerid, 10, 1410.19995117, -1650.09997559, 13.80000019))
    {
        if(!GateOpenStatus)
        {
            MoveObject(GateOpen, 1410.09997559, -1650.09997559, 10.80000019, 3);
            SendClientMessage(playerid, 0xEF994300, "You have opened the gate.");
            GateOpenStatus = true;
        }
        else
        {
            MoveObject(GateOpen, 1410.19995117, -1650.09997559, 13.80000019, 3);
            SendClientMessage(playerid, 0xEF994300, "You have closed the gate.");
            GateOpenStatus = false;
        }
    }
    else if(IsPlayerInRangeOfPoint(playerid, 10, 955.70001221,-50.70000076,1002.00000000))
    {
        if(!DoorStatus)
        {
            MoveObject(Door, 955.70001221,-50.59999847,998.20001221, 3);
            DoorStatus = true;
        }
        else
        {
            MoveObject(Door, 955.70001221,-50.70000076,1002.00000000, 3);
            DoorStatus = false;
        }
    }
    return true;
}