Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

AI Error Question

A topic by lena102 created Apr 16, 2023 Views: 313 Replies: 9
Viewing posts 1 to 8

Hi Shaun! Thanks so much for your work on this project--I've been watching the YouTube releases and have found the source code incredibly helpful as I follow along and learn from how you've built these systems!

I realize that you are unlikely to respond to every dummy like me who is struggling with implementing the code, but as I suspect many others will also be trying to mesh this project with elements from your ARPG series, I thought starting a thread might be helpful in case anyone else comes across this particular issue. I have been getting the following error message:

############################################################################################

ERROR in

action number 1

of  Step Event0

for object oBattle:

Variable <unknown_object>.actions(100162, 0) not set before reading it.

 at gml_Script_anon____struct___19____struct___18_gml_GlobalScript_GameData_5117____struct___19____struct___18_gml_GlobalScript_GameData (line 238) -                      var _action = actions[0];

############################################################################################

gml_Script_anon____struct___19____struct___18_gml_GlobalScript_GameData_5117____struct___19____struct___18_gml_GlobalScript_GameData (line 238)

gml_Script_BattleStateSelectAction_gml_Object_oBattle_Create_0 (line 188) -                             var _enemyAction = _unit.AIscript();

gml_Object_oBattle_Step_0 (line 1) - battleState();

_______

Running version IDE v2023.2.1.75.

The crash happens when the enemy acts using the AI function, as the message says, and the first enemy encounter is never affected. It's only happening during subsequent encounters--after escaping from the enemy and fighting it again, while fighting other instances of the same enemy type, or after leaving the test room and returning to battle the respawned defeated enemy a second time. Even then, it's inconsistent in when it happens; sometimes the AI will work fine for a turn or two before crashing. I will also occasionally receive errors like the above, only referencing seemingly random objects in my test room (prop objects--trees and whatever with nothing on them but collision) rather than the <unknown_object> as above. Occasionally the error message will instead be the "trying to index a variable which is not an array" message. All other aspects of the battle have been working fine. 

Clearly something is going wrong with the enemy action array, but with the exception of changing names and sprites, mine is copied directly from the source code. Would be interested to see if anyone else has had a similar issue, and if so, what thoughts might be on what could be causing it. I might just be an idiot. I would be very glad to be told I am if it means a fix!
Developer (1 edit)

Not sure about this one without a closer look. The fact it makes it into the script call means it definitely has an enemy unit to reference, not finding anything in actions just suggests an incorrect definition in GameData but that would cause an error *every* time that enemy type took its turn. You could try using debug mode and then poking around the variable/struct contents at the moment of the crash. It feels like some reference is off somewhere or other or the data is getting malformed. But it's very hard to guess how.

Greetings, Shaun.

I too am running into this same issue and was wondering if you were able to find an adequate solution. I've been struggling with this error for some time and I fear it may further bottleneck my progress unless I remove the ability to re-battle enemies entirely.

I currently don't want to do that so I'm reaching out to you or anyone else who can help. Here is the error message:

___________________________________________
############################################################################################
ERROR in
action number 1
of  Step Event0
for object obj_battlecontroller:
Variable <unknown_object>.hp(100114, -2147483648) not set before reading it.
 at gml_Script_anon____struct___30____struct___29_init_bestiary_gml_GlobalScript_init_bestiary_1982____struct___30____struct___29_init_bestiary_gml_GlobalScript_init_bestiary (line 65) -                                    if (hp < (maxhp * 0.2))
############################################################################################
gml_Script_anon____struct___30____struct___29_init_bestiary_gml_GlobalScript_init_bestiary_1982____struct___30____struct___29_init_bestiary_gml_GlobalScript_init_bestiary (line 65)
gml_Script_battle_state_select_action_gml_Object_obj_battlecontroller_Create_0 (line 226) -                                    var _enemy_action = _unit.ai_script();
gml_Object_obj_battlecontroller_Step_0 (line 1) - battle_state();
I have also run into similar issues where the game would either crash or enemies would use actions that weren't assigned to them. I tried poking around in debug mode but have not found anything different from what I have seen in this thread.

There was one other solution in this thread that worked for others where you would repeat the third argument for the BeginAction script:

begin_action(_unit.id, _enemy_action[0], _enemy_action[1]);
begin_action(_unit.id, _enemy_action[0], _enemy_action[1], _enemy_action[1]);

but for me, I get a different error message saying that the variable is not an array.

~TwinTails100

Thanks so much for the help, really appreciate it! Just got a moment to debug as suggested with breakpoints on the AI script, and it confirms the issue--"actions" is undefined each time before a crash. (Screenshot attached). It's strange because, again, it defines itself just fine for several turns before something goes wrong. I'll keep messing around in debug and see what I can find!

HI! I'm getting exactly the same issue with the exact same response and error message when debugging! not sure how to fix it, was wondering if the actions array was not getting properly reset between battles?

Little bit of an update:

Turns out that adding another "_enemyAction[1]" to the line below in the create event of oBattle allowed me to complete the second battle, and then the game crashed on the third battle, not sure if it's a fluke or not:


//run AI script for that enemy

var _enemyAction = _unit.AIscript();

if (_enemyAction != -1) BeginAction(_unit.id, _enemyAction[0], _enemyAction[1], _enemyAction[1]); 


Normally it would look like this:

//run AI script for that enemy

var _enemyAction = _unit.AIscript();

if (_enemyAction != -1) BeginAction(_unit.id, _enemyAction[0], _enemyAction[1]); 


Hopefully this is helpful!

(1 edit)

I just came up with a theory about why people may be having this problem. Is it possible that when you assign a global struct to an instance and delete that instance, it stays associated with that instance? When you re-battle an enemy, the enemy's instance that was created has a different id to the previous instance that was destroyed.

This occurs when you re-battle an enemy, battle an enemy of the same type, or exit and re-enter the room before re-battling the enemy. Is there a way to refresh global structs to their condition at game start?

EDIT: I fixed the bug! 

Instead of doing this:

global.enemies =
{
    slimeG: 
    {         name: "Slime",
I re-rote the enemies list to be more in line with the players list:
global.enemies = [
    {
        name: "Slime",
Instead of doing it the way Shaun had implemented it, I assigned a unique integer value to each enemy and manually assigned each enemy's name to an enumerator:
oBattleUnitEnemy,enemies[i]);
oBattleUnitEnemy,global.enemies[enemies[i]]);

I advise everyone facing this problem to do what I did.

Developer

Hello, could you describe the process from just downloading the base code to getting this bug to occur? I understand the theory behind the shallow reference of instance_create_depth somehow leading to incorrect garbage collection when the enemy instance is destroyed but I can't seem to replicate the issue on the basis of this theory. Potentially a runner patch of some kind may have fixed this?

Developer

Will take a proper look at all this when I get chance, this error doesn't occur in the final version of the code so I don't believe it ought to be necessary to change this structure (not that you shouldn't do whatever works for you!). Are you seeing this problem when running the "full project", unedited?

Either way this is all very useful information so thank you for sharing.

Developer

I'm still uncertain what's going on here as I am unable to replicate this issue in the manners people have described. If anyone facing this issue could tell me the precise steps taken from downloading the base code through to getting this error it would be very helpful.