N
nagi
Guest
Greetings, first time posting here. I'm trying to make a standard turn-based battle system, but I keep having trouble when starting the battle from a script.
I'm trying to pass enemy objects as arguments, so the script assigns them to the enemy array in the battle_logic object. Here's my code:
Calling the script
Contents of the script
obj_battle_logic creation code
Problem is, everything works properly... except enemy1 is never created.
It worked, however, when using instance_create while initializing the enemy array directly in the battle_logic object.
When trying to attack the non-existant enemy, the following error occurs (note that I hardcoded enemy[0] for testing purposes only).
Any help is greatly appreciated.
I'm trying to pass enemy objects as arguments, so the script assigns them to the enemy array in the battle_logic object. Here's my code:
Calling the script
Code:
if (keyboard_check_pressed(vk_f5) && room == test_room)
script_execute(script_battle_start, obj_battle_enemy1);
Code:
//Used to start a battle
//argument0, 1, 2 are the enemies to spawn (min. 1)
room_goto(room_battle);
instance_create(0, 0, obj_battle_logic);
//Create enemies up to the number of arguments passed
for (i = argument_count - 1; i >= 0; i--)
obj_battle_logic.enemy[i] = instance_create(0, 0, argument[i]);
Code:
//Initializing enemy array
for (i = 0; i < 3; i++)
enemy[i] = noone;
It worked, however, when using instance_create while initializing the enemy array directly in the battle_logic object.
When trying to attack the non-existant enemy, the following error occurs (note that I hardcoded enemy[0] for testing purposes only).
Code:
___________________________________________
############################################################################################
FATAL ERROR in
action number 2
of Step Event0
for object obj_battle_atk_pointer:
Variable <unknown_object>.<unknown variable>(100008, -2147483648) not set before reading it.
at gml_Script_script_battle_damage_normal (line 5) - obj_battle_logic.enemy[0].life -= (argument0 - obj_battle_logic.enemy[0].def);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_script_battle_damage_normal (line 5)
called from - gml_Object_obj_battle_atk_pointer_StepNormalEvent_2 (line 10) - script_execute(script_battle_damage_normal, dmg);
Any help is greatly appreciated.