Steps before Create?

S

Soren11112

Guest
My step events seem to run before my create events. Because what happens is I get an error on my enemies creation. The error says that state is not defined.

All the code on my create event:
var state = asset_get_index(scr_guard1static)
//Variables
guardhp = 100;
guardSpeed = 3.8;
aggroRange = 300;

All the code on my step event:
//Guard Death
if guardhp <= 0
{
instance_create(guardstandard.x,guardstandard.y,guardknockedoutob)
instance_destroy();
}
script_execute(state)
 
S

Soren11112

Guest
"var state" means that the state variable will only be in the create event. Change "var state" to "state".
I still get this error:
FATAL ERROR in
action number 1
of Create Event
for object guardstandard:

asset_get_index argument 1 incorrect type (0) expecting a String (YYGS)
at gml_Object_guardstandard_CreateEvent_1 (line 1) - state = asset_get_index(scr_guard1static)
 

TheBroman90

Member
I'm not sure what asset_get_index is used for. But what happens if you change it to:
Code:
state = scr_guard1static;
 
S

Soren11112

Guest
Now I face another issue on my AI, it does nothing. Here is guard1static:

//Gets guard stuff
var colx = guardstandard.x - 5;
var coly = guardstandard.y - 5;
var colx2 = guardstandard.x + 5;
var coly2 = guardstandard.y + 5;
//Guard Stuff
if(collision_rectangle(colx,coly,colx2,coly2,playerob,false,true) = true){
if(collision_line(guardstandard.x,guardstandard.y,playerob.x,playerob.y,wallob,true,false) = false){
while(1==1){
state = scr_guardfollow;
};
};
};
_________________________________________________________________________________________________________________________________________________________________________
Here is guardfollow:

move_towards_point(playerob.x,playerob.y,3.8);
 

TheBroman90

Member
Hmm. In guard1static, if you instead try something like this:
Code:
if point_distance(x, y, playerob.x, playerob.y) < 5
{
    if !collision_line(x, y, playerob.x, playerob.y, wallob, true, false)
    {
        state = scr_guardfollow;
    }
}
 
For future reference, the reason why 'asset_get_index' was throwing you an error was because you supplied the asset id to it, which is just a number, where the function was expecting a string value. So, for example, if you would have done the following:

Code:
state = asset_get_index("scr_guard1static");
... It would have worked. Of course, in the above scenario, the entire function call is pointless. If you know the exact asset you need, then just supply it. The use of 'asset_get_index' is better served fro dynamic resource building. An example, to use yours as a base, would be the following:

Code:
// Assumes you have the scripts 'scr_gaurd1static', 'scr_guard2static', 'scr_guard1dynamic', and 'scr_guard2dynamic'

var guard_num = 1,
    ai_type = "dynamic";

state = asset_get_index("scr_guard" + string(guard_num) + ai_type); // Would obtain the script id for 'scr_guard1dynamic'.
Hope this helps!
 
S

Soren11112

Guest
For future reference, the reason why 'asset_get_index' was throwing you an error was because you supplied the asset id to it, which is just a number, where the function was expecting a string value. So, for example, if you would have done the following:

Code:
state = asset_get_index("scr_guard1static");
... It would have worked. Of course, in the above scenario, the entire function call is pointless. If you know the exact asset you need, then just supply it. The use of 'asset_get_index' is better served fro dynamic resource building. An example, to use yours as a base, would be the following:

Code:
// Assumes you have the scripts 'scr_gaurd1static', 'scr_guard2static', 'scr_guard1dynamic', and 'scr_guard2dynamic'

var guard_num = 1,
    ai_type = "dynamic";

state = asset_get_index("scr_guard" + string(guard_num) + ai_type); // Would obtain the script id for 'scr_guard1dynamic'.
Hope this helps!
Thanks!
 

HayManMarc

Member
This bit of code you have:
script_execute(state)
seems suspect to me. Is "state" a script resource you've already defined?
 
S

Soren11112

Guest
For future reference, the reason why 'asset_get_index' was throwing you an error was because you supplied the asset id to it, which is just a number, where the function was expecting a string value. So, for example, if you would have done the following:

Code:
state = asset_get_index("scr_guard1static");
... It would have worked. Of course, in the above scenario, the entire function call is pointless. If you know the exact asset you need, then just supply it. The use of 'asset_get_index' is better served fro dynamic resource building. An example, to use yours as a base, would be the following:

Code:
// Assumes you have the scripts 'scr_gaurd1static', 'scr_guard2static', 'scr_guard1dynamic', and 'scr_guard2dynamic'

var guard_num = 1,
    ai_type = "dynamic";

state = asset_get_index("scr_guard" + string(guard_num) + ai_type); // Would obtain the script id for 'scr_guard1dynamic'.
Hope this helps!
I had a question about this, if I had many objects of the same name could I use this to use one specific object as a target? Like lets say I had 100 obj_wall could I use this to destroy one specific wall?
 
I had a question about this, if I had many objects of the same name could I use this to use one specific object as a target? Like lets say I had 100 obj_wall could I use this to destroy one specific wall?
This is for the object as a whole. What you're looking for is the id.
 
Any function that returns an id will be what you need; check the manual to see which ones do. Keep in mind that only one id can be returned at a time, so you'll have to design systems that are capable of returning more than one.
 
Top