Variables and if statements

Discuss all aspects related to modding Zandronum here.
Post Reply
noissessop
New User
Posts: 2
Joined: Sat May 18, 2013 8:38 pm

Variables and if statements

#1

Post by noissessop » Sat May 18, 2013 8:43 pm

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

Ijon Tichy
Frequent Poster Miles card holder
Posts: 901
Joined: Mon Jun 04, 2012 5:07 am

RE: Variables and if statements

#2

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

Code: Select all

int ItemsCollected = 0;

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

script 2 (void)
{
    if (ItemsCollected > 5)
    {
        SetResultValue(1);
    }
    else
    {
        SetResultValue(0);
    }
}
Last edited by Ijon Tichy on Sat May 18, 2013 9:22 pm, edited 1 time in total.

noissessop
New User
Posts: 2
Joined: Sat May 18, 2013 8:38 pm

RE: Variables and if statements

#3

Post by noissessop » Sat May 18, 2013 9:47 pm

Thank you, this works perfectly

User avatar
ibm5155
Addicted to Zandronum
Posts: 1641
Joined: Tue Jun 05, 2012 9:32 pm
Location: Somewhere, over the rainbow

RE: Variables and if statements

#4

Post by ibm5155 » Sat May 18, 2013 10:28 pm

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)
Projects
Cursed Maze: DONE, V2.0
Zombie Horde - ZM09 map update: [3/15/13]
Need help with English? Then you've come to the right place!

<this post is proof of "Decline">

Ijon Tichy
Frequent Poster Miles card holder
Posts: 901
Joined: Mon Jun 04, 2012 5:07 am

RE: Variables and if statements

#5

Post by Ijon Tichy » Sun May 19, 2013 12:44 am

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.

User avatar
ibm5155
Addicted to Zandronum
Posts: 1641
Joined: Tue Jun 05, 2012 9:32 pm
Location: Somewhere, over the rainbow

RE: Variables and if statements

#6

Post by ibm5155 » Sun May 19, 2013 1:18 am

:o
master ijon, :oooooooooooooooo

I feel like a newbie now.
Projects
Cursed Maze: DONE, V2.0
Zombie Horde - ZM09 map update: [3/15/13]
Need help with English? Then you've come to the right place!

<this post is proof of "Decline">

Lollipop
Zandrone
Posts: 1124
Joined: Tue Jul 24, 2012 10:34 am
Location: Denmark

RE: Variables and if statements

#7

Post by Lollipop » Mon May 27, 2013 12:12 pm

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

just how does this script work?
Combinebobnt wrote:i can see the forum league is taking off much better than the ctf ones
GalactusToday at 1:07 PM
are you getting uncomfortable jap
feeling something happen down there

User avatar
Ænima
Addicted to Zandronum
Posts: 3582
Joined: Tue Jun 05, 2012 6:12 pm

RE: Variables and if statements

#8

Post by Ænima » Mon May 27, 2013 12:55 pm

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;
Reinforcements: midgame Survival joining/respawning
Doom64: Unabsolved: Doom64 + Diablo II
ZandroSkins: a pack made by our community
AeniPuffs: 3D blood and bullet puff effects, free to use for your own mods
Squad Radio: a WASD-based radio chat menu, add your own custom sounds!
Mercenaries (on hold)
Image

Krispy
 
Posts: 88
Joined: Tue Jun 05, 2012 9:37 pm
Location: Michigan

RE: Variables and if statements

#9

Post by Krispy » Mon May 27, 2013 7:53 pm

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.

Lollipop
Zandrone
Posts: 1124
Joined: Tue Jul 24, 2012 10:34 am
Location: Denmark

RE: Variables and if statements

#10

Post by Lollipop » Tue May 28, 2013 1:53 pm

Æ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 :(
Combinebobnt wrote:i can see the forum league is taking off much better than the ctf ones
GalactusToday at 1:07 PM
are you getting uncomfortable jap
feeling something happen down there

User avatar
Ænima
Addicted to Zandronum
Posts: 3582
Joined: Tue Jun 05, 2012 6:12 pm

RE: Variables and if statements

#11

Post by Ænima » Tue May 28, 2013 2:42 pm

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".)
Last edited by Ænima on Tue May 28, 2013 2:45 pm, edited 1 time in total.
Reinforcements: midgame Survival joining/respawning
Doom64: Unabsolved: Doom64 + Diablo II
ZandroSkins: a pack made by our community
AeniPuffs: 3D blood and bullet puff effects, free to use for your own mods
Squad Radio: a WASD-based radio chat menu, add your own custom sounds!
Mercenaries (on hold)
Image

Lollipop
Zandrone
Posts: 1124
Joined: Tue Jul 24, 2012 10:34 am
Location: Denmark

RE: Variables and if statements

#12

Post by Lollipop » Thu May 30, 2013 3:12 pm

thank you very much, you are always so friendly :)
Combinebobnt wrote:i can see the forum league is taking off much better than the ctf ones
GalactusToday at 1:07 PM
are you getting uncomfortable jap
feeling something happen down there

Post Reply