• 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!

[Solved] "Simple" Calculator HELP ME!

S

Soren11112

Guest
Code:
var num1 = 1;
var num2 = num1*2;
var num3 = num2*2;
var num4 = num3*2;
var num5 = num4*2;
var num6 = num5*2;
var num7 = num6*2;
var num8 = num7*2;
var num9 = num8*2;
var random1 = random_range(1,9);
var random2 = random_range(1,9);
var random3 = random_range(1,9);
var random4 = random_range(1,9);
var random5 = random_range(1,9);
var random6 = random_range(1,9);
var random7 = random_range(1,9);
var random8 = random_range(1,9);
var random9 = random_range(1,9);
var num1row1 = num+random1;
draw_text(0,0,num1row1);
What I'm trying to do above is make a calculator for a question that a friend posed. My problem is on the second from the bottom row, is there any way I can do something like
Code:
 "num"+random1
and if random1 was 2 it would appear as
Code:
 num2
?
 

Binsk

Member
Use arrays, not single variables.

An array is essentially a list of variables where you specify the value you want with an index.

An example would be:
Code:
_num[0] = 1;
_num[1] = _num[0] * 2;
//etc.

_num[_random1] // like this
It is faster to define the array backwards (because of how the memory is allocated) but not necessary.

Sorry, short response. Trying to code with a phone sucks. :p
 
Last edited:
S

Soren11112

Guest
Use arrays, not single variables.

An array is essentially a list of variables where you specify the value you want with an index.

An example would be:
Code:
_num[0] = 1;
_num[1] = _num[0] * 2;
//etc.

_num[_random1] // like this
It is faster to define the array backwards (because of how the memory is allocated) but not necessary.

Sorry, short response. Trying to code with a phone sucks. :p
Thanks, you got your point across it doesn't need to be longer.
 
Top