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

Legacy GM Question About Arrays

L

Lilvulpix

Guest
Hello again ladies and gentlemen.
The question;
Is it a good idea to have one script dedicated to a list of arrays? (A script that just has the arrays)
Or should I just use the interface to create a parent object for each base creature type?

Details;
I am working on a concept where you raise animals/monsters. The idea is that you click on a plot of land that the player owns and choose an animal/monster to raise in that spot. Now, these creatures will have stats that are used later in the game. After some reading I thought 2D Arrays were a good choice. However my experience and knowledge of GML is pretty low. I am not sure if I can just make one script dedicated to setting up the parent information for the various creature types, or if it needs to be created within a script that actually uses it. (Local vs global... I think? Local means within the script only correct?)

I am mostly using drag and drop, but trying to learn as much as I can about the GML along the way for ease of life later on.


Thank you, for reading this mess of text at least!
-Lilvulpix
 
N

noino

Guest
What I think, before diving too far into the advanced side of GML, perhaps learn all the basic aspects of the language and exclusively utilize it.
If it's possible to do 3d arrays use those, or create more arrays to store the variables and synchronize them accordingly
say, for example,
Create Event:
Code:
cellsize = //size of "grid"

animal[0,0] = 0;
(variable)[xx,yy] = 0;
(variable)[xx,yy] = 0;
Draw Event:
Code:
//Cycling through all the slots
for(xx = 0; xx < room_width; xx += cellsize){
     for(yy = 0; yy < room_height; yy += cellsize){
          if(//event){
               //Change slot to be certain animal if requirements are met
               animal[xx,yy] = "horse";
               initSlotVariables(xx,yy);
          }
          if(animal[xx,yy] != 0){
               //of course you can do anything you want here
               draw_sprite(spr_horse,0,xx,yy);
          }
     }
}
Then later in a script
InitSlotVariables:
Code:
///initSlotVariables
xx = argument0;
yy = argument1;

//Set the slot's other variables if current slot is "horse"
if(animal[xx,yy] = "horse"){
     (variable)[xx,yy] = (value);
     (variable)[xx,yy] = (value);
}
//You can add more animal initializations in else if statements here
//Reset the variables if it's ever changed to be empty
else{
     (variable)[xx,yy] = 0;
     (variable)[xx,yy] = 0;
}
and so on. I'm sure people have better ways of performing your requirements, and this is just a basic example of how the data could be stored on the array

EDIT: I want you to take this code as somewhere to learn from, not to copy directly. Once you analyse the logic it's easy to understand, maybe then you can discover a more effective approach.
 
Last edited by a moderator:
L

Lilvulpix

Guest
EDIT: I want you to take this code as somewhere to learn from, not to copy directly. Once you analyze the logic it's easy to understand, maybe then you can discover a more effective approach.
This advice will most certainly be followed. I find it pointless to simply copy a code if I cannot wrap my mind around it first. I try to ask general questions unless I am trying to debug something in particular (my first post on these forums actually) in order to force myself to learn, rather than 'monkey see, monkey do' things!
 
Top