YoSniper
Member
Hello community,
I recently ran into an issue using arrays that I don't remember experiencing in Game Maker 8.
Basically, I am trying to initialize values to be stored in a persistent object that basically tracks my game data, and is responsible for saving to files and loading data back from them. Within this object, I keep track of data for three separate save slots.
This is a segment of the Create Event from this object:
Note that the _selected arrays are meant to be 1D, while the _unlocked arrays have to be 2D. In GM8, rather than use the comma notation, I would have initialized them as
but GM:Studio apparently doesn't like it when I do that, as it detects a syntax error.
This isn't the problem so much, until I try to instantiate a Player object, which is given its character attribute from this object.
Script create_player(x, y, character, is_npc)
This script is called from within a load_game script as such:
Script load_game(save_slot)
I expect that by default, the Player would be assigned the string value "KID" to its character attribute. But what I get instead is the complete list { {"KID", "KID", "KID", } }. This manifests itself as an error later.
Why is the full list getting passed to my Player object. At first I thought it was because I'm calling a script from within another script, both of which utilize argument0 in their code. However, after eliminating that problem, I still get the same issue.
Are all arrays initialized as 2D and I have to add a second index to all of them? What is happening?
Any help is appreciated.
I recently ran into an issue using arrays that I don't remember experiencing in Game Maker 8.
Basically, I am trying to initialize values to be stored in a persistent object that basically tracks my game data, and is responsible for saving to files and loading data back from them. Within this object, I keep track of data for three separate save slots.
This is a segment of the Create Event from this object:
Code:
var ii, jj;
for(ii = 0; ii < 3; ii += 1) {
character_selected[ii] = "KID";
gun_selected[ii] = "NORMAL";
}
for(ii = 0; ii < 6; ii += 1) {
for(jj = 0; jj < 3; jj += 1) {
if ii < 5 {
guns_unlocked[ii, jj] = false;
}
characters_unlocked[ii, jj] = false;
}
}
Code:
guns_unlocked[ii][jj] = false;
This isn't the problem so much, until I try to instantiate a Player object, which is given its character attribute from this object.
Script create_player(x, y, character, is_npc)
Code:
/*
Creates an instance of a Player object and gives it the input character.
The ID of the created instance is returned.
*/
var new_inst, obj_index;
if argument3 {
obj_index = NPC;
} else {
obj_index = Player;
}
new_inst = instance_create(argument0, argument1, obj_index);
new_inst.character = argument2;
if argument2 == "WIMPLY" {
new_inst.mask_index = sprBigWimplyMask;
}
return new_inst;
Script load_game(save_slot)
Code:
/*
Loads the saved game from World attribute data, including the room, player's x and y,
difficulty, game time, and characters and guns unlocked.
*/
with(CharacterParent) {
instance_destroy();
}
room = World.save_room[argument0];
create_player(World.save_x[argument0], World.save_y[argument0],
World.character_selected[argument0], false);
if World.difficulty[argument0] > 1 {
if not instance_exists(Clock) {
instance_create(0, 0, Clock);
}
Clock.timer = get_clock_time(World.save_id[argument0]);
}
Why is the full list getting passed to my Player object. At first I thought it was because I'm calling a script from within another script, both of which utilize argument0 in their code. However, after eliminating that problem, I still get the same issue.
Are all arrays initialized as 2D and I have to add a second index to all of them? What is happening?
Any help is appreciated.