Simple Array (Mind Blank!)
by David Taylor · in Torque Game Builder · 11/13/2008 (7:39 pm) · 1 replies
Hi all. I haven't coded for months, and I'm extremely rusty. I decided to make a simple shooter involving different coloured pickups each of varying strength.
The basic concept is that there are 4 colours, each of which has 5 "power ratings".
So the player picks up a red pickup, and they have Red Power 1. They pick up another red one, and it goes to Red Power 2. But then they pick up a yellow, and it switches to Yellow Power 1, etc.
Can someone please remind me how to make a simple 4x5 array so that when I introduce the gui images into the scene, I can literally just tell it which one to display, and the appropriate one gets displayed? I'd rather do it this way, all in the same pickup class, than have, say, a redpickupclass, a yellowpickupclass, and so on.
So, yeah - I have 20 gui images, and I want them to have unique values so that I can tell Torque to run through the array, find the right one, and I can go from there.
The basic concept is that there are 4 colours, each of which has 5 "power ratings".
So the player picks up a red pickup, and they have Red Power 1. They pick up another red one, and it goes to Red Power 2. But then they pick up a yellow, and it switches to Yellow Power 1, etc.
Can someone please remind me how to make a simple 4x5 array so that when I introduce the gui images into the scene, I can literally just tell it which one to display, and the appropriate one gets displayed? I'd rather do it this way, all in the same pickup class, than have, say, a redpickupclass, a yellowpickupclass, and so on.
So, yeah - I have 20 gui images, and I want them to have unique values so that I can tell Torque to run through the array, find the right one, and I can go from there.
About the author
Torque Owner Shaz
for (%color=0; %color < 4; %color++) { switch (%color) { case 0: %colortxt = "Red"; case 1: %colortxt = "Yellow"; .... } for (%power=0; %power < 5; %power++) { icon[%color][%power] = %colortxt SPC "Power" SPC %power + 1; // or images[%color][%power] = %colortxt @ "Power" @ %power + 1 @ "ImageMap"; // would give you the exact name of the image map, assuming something like RedPower1ImageMap } }%power goes from 0 to 4 (< 5) because array elements start at 0. So you have to add 1 to it when assigning the image.
Although, if you have one variable holding the color, and another holding the power, I don't see why you need an array at all - you can just build your image map name dynamically, using %colortxt @ "Power" @ %power + 1 @ "ImageMap".