D
Drago the Shinigami
Guest
Hello,
I'm currently working on a script to determine turn order for a turn-based battle system. Unfortunately, I keep getting the same error message, and I can't see how it's happening.
Here's the code for the script:
And here's the error message:
I'm currently working on a script to determine turn order for a turn-based battle system. Unfortunately, I keep getting the same error message, and I can't see how it's happening.
Here's the code for the script:
Code:
global.BattleOrder = 0
var templist = array_create(instance_number(Battler_Template))
//create list
var inst = 0
for(var i = 0; i < instance_number(Battler_Template); i++)
{
var tempid = instance_find(Battler_Template,i)
array_set(templist, i, tempid)
}
//sort list
for(var j = array_length_1d(templist); j > 0 ;j--)
{
show_debug_message("j = " + string(j))
for(var k = 0; k < j; k++)
{
var foundhome = false
var speed1a = array_get(templist, j).AGL
var speed1b = array_get(templist, j).Action_Speed
var speed2a = array_get(templist, k).AGL
var speed2b = array_get(templist, k).Action_Speed
if(speed1a + speed1b <= speed2a + speed2b && !foundhome)
{
var temp = array_get(templist, j)
array_set(templist, j, array_get(templist, k))
array_set(templist, k, temp)
foundhome = true
}
}
}
//finalize list
global.BattleOrder = array_create(array_length_1d(templist))
for(var i = 0; i < array_length_1d(templist); i++)
{
array_set(global.BattleOrder, i, array_get(templist, i))
}
If anyone could help me, that would be appreciated.___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Other Event: User Defined 0
for object Fight:
array_get :: Index [0,19] out of range [1,19]
at gml_Script_DetermineBattleOrder (line 19) - var speed1a = array_get(templist, j).AGL
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_DetermineBattleOrder (line 19)
called from - gml_Object_Fight_Other_10 (line 7) - DetermineBattleOrder()
called from - gml_Object_Fight_Mouse_1 (line 3) - event_user(0)