• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

For every increment add part to script arguments

N

NoFontNL

Guest
Title may be unclair, but I'll explain in a bit.
I have a variable called 'size', when size is higher than 2 I need to add a part in the middle of a script.
So here are some examples.

size=3
scr_script(sprite,image,0,0,0,sprite2,image2,0,0,-64);

size=4
scr_script(sprite,image,0,0,0,spriteMiddle,imageMiddle,0,0,-64,sprite2,image2,0,0,-128);

size=5
scr_script(sprite,image,0,0,0,spriteMiddle,imageMiddle,0,0,-64,spriteMiddle,imageMiddle,0,0,-128,sprite2,image2,0,0,-192);

Hope you'll get the idea.
Btw. I do not like if statements. Then for example size=n wouldn't work for every n

Any help would be appreciated!
 

Amon

Member
Why not pass size as a parameter of the script and grab whatever value you need and calculate from there?
 

chamaeleon

Member
Trying to use the size variable to determine how many arguments need to be placed in the script.

I'll try this, thanks!
Or if there are variations you need to include, you could use a single parameter that is an array or some other suitable data structure containing all the variable amount of data.
 

Simon Gust

Member
You can use argument_count and compare against how many arguments provided to then command what logic to execute
Code:
if (argument_count == 10)
{
// execute what would've been the size == 3 script
}
else
if (argument_count == 16)
{
// execute what would've been the size == 4 script
}
else
{
// execute what would've been the size == 5 script
}
Just make sure that you initialize the arguments inside this if-clause.
 
Top