GML Scene slow loading causing system not to find object

F

Frisk17

Guest
See I'm working on a RPG was working on the battle system.
As the title suggests the scene is actually loading in milli-seconds but function called in micro-seconds so the point is that the title might not be so APPROPRIATE to the discussion.

My script:
Code:
///@desc battle_enemy
///@arg name
///@arg sprite_idle
///@arg sprite_atk
///@arg hp
///@arg dmg
///@arg atk_name
///@arg ckw
///@arg altcw
///@arg sckw
///@arg bckw
///@arg altbckw
///@arg sbckw
///@arg can_escape

var name = argument[0];
var sprite_idle = argument[1];
var sprite_atk = argument[2];
var hp = argument[3];
var dmg = argument[4];
var atk_name = argument[5];
var ckw = argument[6];
var altckw = argument[7];
var sckw = argument[8];
var bckw = argument[9];
var altbckw = argument[10];
var sbckw = argument[11];
var can_escape = argument[12];

room_goto(RM_BATTLE);
obj_player.visible = false;

var e = obj_enemy;

e.name = name;
e.sprite_idle = sprite_idle;
e.sprite_atk = sprite_atk;
e.hp = hp;
e.dmg = dmg;
e.attack_name = atk_name;
e.ckw = ckw;
e.altckw = altckw;
e.sckw = sckw;
e.bckw = bckw;
e.altbckw = altbckw;
e.sbckw = sbckw;
e.can_escape = can_escape;
   
e.sprite_index = sprite_idle;
So the error is that it can't find e and my assumption is that e is tried to find before the scene even starts. (+ don't ask what those weird vars are)
I even tried until loop which kind of breaks the main loop and then force quit..

A help would be appreciated..
PS: If that sounds convincing
 

rIKmAN

Member
See I'm working on a RPG was working on the battle system.
As the title suggests the scene is actually loading in milli-seconds but function called in micro-seconds so the point is that the title might not be so APPROPRIATE to the discussion.

My script:
Code:
///@desc battle_enemy
///@arg name
///@arg sprite_idle
///@arg sprite_atk
///@arg hp
///@arg dmg
///@arg atk_name
///@arg ckw
///@arg altcw
///@arg sckw
///@arg bckw
///@arg altbckw
///@arg sbckw
///@arg can_escape

var name = argument[0];
var sprite_idle = argument[1];
var sprite_atk = argument[2];
var hp = argument[3];
var dmg = argument[4];
var atk_name = argument[5];
var ckw = argument[6];
var altckw = argument[7];
var sckw = argument[8];
var bckw = argument[9];
var altbckw = argument[10];
var sbckw = argument[11];
var can_escape = argument[12];

room_goto(RM_BATTLE);
obj_player.visible = false;

var e = obj_enemy;

e.name = name;
e.sprite_idle = sprite_idle;
e.sprite_atk = sprite_atk;
e.hp = hp;
e.dmg = dmg;
e.attack_name = atk_name;
e.ckw = ckw;
e.altckw = altckw;
e.sckw = sckw;
e.bckw = bckw;
e.altbckw = altbckw;
e.sbckw = sbckw;
e.can_escape = can_escape;
  
e.sprite_index = sprite_idle;
So the error is that it can't find e and my assumption is that e is tried to find before the scene even starts. (+ don't ask what those weird vars are)
I even tried until loop which kind of breaks the main loop and then force quit..

A help would be appreciated..
PS: If that sounds convincing
Post the exact error message.

If the error is coming from somewhere other than this script then it's likely whatever is trying to access "e" cannot find it because it does not exist outside of this script due to it being declared with the "var" keyword, making it a local variable.
 
F

Frisk17

Guest
So I removed the temporary keyword and it's called at player which is persistent.
Error:
Unable to find any instance for object index '10' name 'obj_enemy'
at gml_Script_battle_enemy (line 36) - e.sprite_idle = sprite_idle;
 
F

Frisk17

Guest
I've got only 1 instance in RM_BATTLE room so no chance not being there after loading the scene.
 
Ok, so set an alarm (or better yet, load your scene in such a way that you know when it's finished) and call the script after that.
 

TheouAegis

Member
What Refresher is saying is that the room doesn't actually change until the current event has finished running. You need to essentially run the code over multiple steps.
 
F

Frisk17

Guest
I did it I made them global vars and made another script set_enemy which is called in the room start event of enemy(indirectly by an event system which is shown in friendly cosmonauts tutorial)
 
Top