Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
cyber-menace

Adding to Variables

Recommended Posts

I have an easy question this time. What is one easy line of scripting that will add 1 to a variable. I'm going to have this adding up to six. I need it for my current map. (Disabling bombs gives the variable a point, if all 6 are disabled script 1, the bomb script, stops!)

Share this post


Link to post

Wanna know how to add 2?
variable = variable + 2;

Wanna know how to add 3?
variable = variable + 3;

Wanna know how to add 4?
variable = variable + 4;

Wanna know how to add 5?
variable = variable + 5;

Wanna know how to add 2 variables together?
combo = variableA + varibleB;

Wanna know how to subtract 2 from a variable?
variable = variable - 2;

Wanna know how to add 2 variables then subtract 2?
combo = varA + varB -2;

Heh, you know about the Zdoom reference right? Well Randy's making a new one since this one is so old. Cool.

Share this post


Link to post
Epyo said:

Wanna know how to add 2?
variable = variable + 2;

Wanna know how to add 3?
variable = variable + 3;

Wanna know how to add 4?
variable = variable + 4;

Wanna know how to add 5?
variable = variable + 5;

Wanna know how to add 2 variables together?
combo = variableA + varibleB;

Wanna know how to subtract 2 from a variable?
variable = variable - 2;

Wanna know how to add 2 variables then subtract 2?
combo = varA + varB -2;

Heh, you know about the Zdoom reference right? Well Randy's making a new one since this one is so old. Cool.

Yes but how do you add 1?!?!?

Share this post


Link to post

omg!%^

var++; //add one to var
var += 2; //add two to var
var += 3; //add three to var
var += x; //add x to var
var -= 7; //subtract 7 from var
var--; //subtract 1 from var
var *= 2; //same as var = var * 2;
var /= 4; //same as var = var / 4;

Share this post


Link to post

uh,

x += 10;
x /= 1728;
x *= 751;
tada!

you can also do stuff like:
x *= 0.75; //75% of x
x /= 0.5;  //double x
but those will only work if x is an int, not fixed point. if x is fixed point (1.2 or something like that) you need to do:
x = fixedmul(x, 0.75);
x = fixeddiv(x, 0.5);
(aside from the last two lines, this is all fairly standard programming stuff avaliable in most (if not all) programming languages, in case you wanted to know or something :P )

Share this post


Link to post
Nanami said:

You didn't explain how to subtract two-digit numbers. =/


rofl the same exact way

x -= 25;
x -= 38343;

Share this post


Link to post
Cyb said:

rofl the same exact way

x -= 25;
x -= 38343;

What if my variable is not named "x"?

Share this post


Link to post

Can anyone else confirm that cyber-menace is right? I really need this in a script I'm writing. But I don't want it to go havoc and break my computer or something.

Share this post


Link to post

after careful testing I can indeed say he is correct. however you need to uh, initalize those varible thingies otherwise it won't work...

Share this post


Link to post
Cyb said:

however you need to uh, initalize those varible thingies otherwise it won't work...

Where can I do that? Is it expensive?

Share this post


Link to post

Initializing is done before the scripts. It's quite simple. Here's a couple of examples.

#include "zcommon.acs"

int variablename
int forcef

(Scripts go here)
See it's that simple. So give'er a try.

Share this post


Link to post
boris said:

Where can I do that? Is it expensive?


nah, it's like 10 bucks/euros a variable or something so I guess you should try not to use too many. head to your local variable initilization store (if you don't have one there's an internet site, variableinitilizationsonline.com) and pay them and they'll get it done for you

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×