Hopefully this makes sense.
Here are 3 variables:
global.iteminventory0[2]
global.iteminventory1[2]
global.iteminventory2[2]
Here is the code:
if global.iteminventory0[1] = "Least Potion"
{global.iteminventory0[2] -= 1
global.life += 50}
I pretty much have the code set as a script, and I want to use arguments to specify the number after inventory (something like global.iteminventory(argument0) so that I don't have to make several copies of the script for global.iteminventory0, global.iteminventory1 etc.
Any ideas?
Changing a string inside a variable?
Started by Spiritwolf, Mar 04 2012 07:59 PM
3 replies to this topic
#1
Posted 04 March 2012 - 07:59 PM
#2
Posted 04 March 2012 - 08:06 PM
In your case, use a 2D array instead of multiple 1D arrays to store your inventories.
To set it up:
Then to reference it:
GameGeisha
PS:
- Remember that array indices in GM start with 0, not 1.
- Simple coding questions like this belongs in Novice Q&A.
To set it up:
var i; for (i = 0; i < 3; i += 1) global.iteminventory[i, 0] = ""; //What goes here? global.iteminventory[i, 1] = ""; //Name? global.iteminventory[i, 2] = 0; //Amount? }
Then to reference it:
if (global.iteminventory[0, 1] == "Least Potion") {
global.iteminventory[0, 2] -= 1;
global.life += 50;
}
GameGeisha
PS:
- Remember that array indices in GM start with 0, not 1.
- Simple coding questions like this belongs in Novice Q&A.
#3
Posted 04 March 2012 - 09:05 PM
PS:
- Remember that array indices in GM start with 0, not 1.
- Simple coding questions like this belongs in Novice Q&A.
Yes, I am aware of this. The [0] array is used elsewhere in the game for a different interface.
Shoot, are 2d arrays really that easy?
#4
Posted 04 March 2012 - 09:08 PM
If you look up "array" in the manual, you'll see from the example given that it really is this easy.Shoot, are 2d arrays really that easy?
GameGeisha
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











