Page 1 of 1

Variables and if statements

Posted: Sat May 18, 2013 8:43 pm
by noissessop
I'm trying to learn ACS so I can make better maps but i'm struggling a bit. I've tried looking for the answer to this on the zdoom wiki but haven't had any luck.
What I want to do is have one script set a variable (e.g. set ItemCollected to 1) and then have another script use the variable in an if statement (If Itemcollected = 1) operation 1 else operation 2. I just need to know how to set a variable and the syntax I need to use in an if statement

RE: Variables and if statements

Posted: Sat May 18, 2013 9:22 pm
by Ijon Tichy

Code: Select all

int ItemsCollected = 0;

script 1 (int inc)
{
    ItemsCollected += inc;
}

script 2 (void)
{
    if (ItemsCollected > 5)
    {
        SetResultValue(1);
    }
    else
    {
        SetResultValue(0);
    }
}

RE: Variables and if statements

Posted: Sat May 18, 2013 9:47 pm
by noissessop
Thank you, this works perfectly

RE: Variables and if statements

Posted: Sat May 18, 2013 10:28 pm
by ibm5155
Hmm if acs works like ansi c.
if you do If (Itemcollected = 1) this sentence´ll be always true, so it´ll enter on the if state always, to compare you need two equals -> If (Itemcollected == 1)

RE: Variables and if statements

Posted: Sun May 19, 2013 12:44 am
by Ijon Tichy
That's explicitly a false statement. Assignments in if statements are not allowed.

Also, "if (herp = 0)" is guaranteeed to fail, because the value herp is being set to (0) is false. It's not a guaranteed true.

RE: Variables and if statements

Posted: Sun May 19, 2013 1:18 am
by ibm5155
:o
master ijon, :oooooooooooooooo

I feel like a newbie now.

RE: Variables and if statements

Posted: Mon May 27, 2013 12:12 pm
by Lollipop
script 1 (int inc)
{
ItemsCollected += inc;
}

just how does this script work?

RE: Variables and if statements

Posted: Mon May 27, 2013 12:55 pm
by Ænima
Lollipop wrote: script 1 (int inc)
{
ItemsCollected += inc;
}

just how does this script work?
It adds the value of "inc" to "ItemsCollected".

It's a simplified version of

Code: Select all

ItemsCollected = ItemsCollected + inc;

RE: Variables and if statements

Posted: Mon May 27, 2013 7:53 pm
by Krispy
noissessop wrote: I'm trying to learn ACS so I can make better maps
Well there's your problem. ACS doesn't make your maps better. I learned that the hard way.

RE: Variables and if statements

Posted: Tue May 28, 2013 1:53 pm
by Lollipop
Ænima wrote:
Lollipop wrote: script 1 (int inc)
{
ItemsCollected += inc;
}

just how does this script work?
It adds the value of "inc" to "ItemsCollected".

It's a simplified version of

Code: Select all

ItemsCollected = ItemsCollected + inc;
then please slap me and tell me how to give inc a value, because I dont understand, no matter how many times I look into various projects :(

RE: Variables and if statements

Posted: Tue May 28, 2013 2:42 pm
by Ænima
Lollipop wrote:
Ænima wrote:
Lollipop wrote: script 1 (int inc)
{
ItemsCollected += inc;
}

just how does this script work?
It adds the value of "inc" to "ItemsCollected".

It's a simplified version of

Code: Select all

ItemsCollected = ItemsCollected + inc;
then please slap me and tell me how to give inc a value, because I dont understand, no matter how many times I look into various projects :(
With the script you posted, the value of inc gets set using an argument when you call the script. This is because after "script 1", you put "(int inc)" instead of "(VOID)". This is okay. It makes the script more flexible.

For example,

Code: Select all

script 1 (int inc)
 {
     ItemsCollected += inc;
 }

script 2 (void)
{
ACS_Execute(1,0, 555);
}
Here, using the script you gave, I have called it from another script. When I use ACS_Execute, the first parameter is the script I want to execute, the second parameter is almost always zero (this is the map of the script we want to execute, 0 means the current map), and the third number is the argument that we want to put into Script 1. In this case, it's 555.

That means that Script 1 will be executed and "inc" will be 555. (Only for that time though. This does not permenantly set the value of "inc".)

RE: Variables and if statements

Posted: Thu May 30, 2013 3:12 pm
by Lollipop
thank you very much, you are always so friendly :)