GameMaker: Studio

GameMaker: Studio

Vezi statistici:
script_execute(varible) keeps using first script
I can't get an object (obj_nme_loafcat) to use the right script. Instead it will always try to use the script at the top of my scripts folder.

I set a varible in my create event "state = scr_nme_idle_state" then in the step even of the object I try to have the object use the script using "script_execute(state);" but it dosent recognize the varible and will instead set it to 0.

I'm posting what I think is relevent below, I've been looking into this problem for over an hour, the closest thing I could find online relating to this problem was this: https://forum.yoyogames.com/index.php?threads/help-utterly-baffled-at-script_execute.41007/

I am fairly new at this, I wouldent be surprised if I'm just not doing a small, simple thing but I just can't figure it out. Any help would be greatly appriciated.

Thanks for your time

Object create event:
///initialize_enemy
event_inherited();
image_speed=.1;
spd = .5;
state = scr_nme_idle_state;

Object Step event:
///Run_the_current_state
event_inherited();
script_execute(state);

Error message:
FATAL ERROR in
action number 1
of Step Event0
for object obj_nme_loafcat:

Variable obj_nme_loafcat.dir(100002, -2147483648) not set before reading it.
at gml_Script_scr_get_face (line 2) - face = round(dir/90);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_scr_get_face (line 2)
called from - gml_Object_obj_nme_loafcat_StepNormalEvent_1 (line 3) - script_execute(state);
< >
Se afișează 1-13 din 13 comentarii
maras 28 ian. 2019 la 22:19 
Instead of
state = scr_nme_idle_state, script_execute(state);
try to use just
scr_nme_idle_state();
Editat ultima dată de maras; 28 ian. 2019 la 22:20
Thanks for responding so quickly!

Doing this does stop the error, however the object now just stays in place and dosen't move into it's chase state when the player object is nearby.

I'm thinking that since "scr_nme_idle_state();" is in a step even it's executing this script in every frame, essentially keeping it in that state and preventing it from changing into running a new script (like the chase script). Does this sound right or does game maker work differently than this?

I understand you're working with limited information, if I'm leaving out any key details in understanding this problem just let me know, I'll provide what I can. I try to present what I think is relevent so I'm not bogging people down with useless info.

I am curious though as to why it keeps trying to run the first script in my script list all the time. Like if I set it to script_execute(7); it will run the 7th script down the list, so I can have it play the idle script that way, but it's the same problem as before where now it's stuck in that script and I need the script executed to be able to change.

again, thanks for taking your time to help me with this.
OH! I know what may help. Dang I don't know why I didn't think of this earlier. I'm trying to learn game maker by following video tutorials. This is the tutorial I was following:

https://www.youtube.com/watch?v=huvEsQ-U3Is&t=385s

I don't expect you to watch a 17 minute video to be sure, but were you to skim through and look at the code bits, you would see the code I have in my game. I've re-watched this sevral times, as far as I can tell I've copied his code exactly, yet it results in this error. I'm thinking that since this video is so old, maybe he's working with code that is no longer viable in the modern version of game maker?

I hope you find this useful.
One thing you can do to help you understand what is going on is to envoke the debugger. Also using debug messages with meaningful text in them to help you pull the puzzle apart one string at a time. More over the use of break points to stop the program in key events or after key execution(s) have happened can help you watch variables and their values. Stepping through the code one line, script, event, or step at a time.

Things happen so fast at 30/60 steps per second that what you think should happen may in fact not be happening. In fact something totally unforeseen might be happening showing you a bug where you thought it wouldn't be.

Most of the time the answers to my solutions are staring me in the face and I'm too blind to see them in their simplicity. But using the debugger as a lense to peer into my game I find my solutions and feel somewhat dim-witted when I do. "Check the fuses" my grandad would say. "Why rebuild the engine if it's only a fuse?"

EDIT: if you need some education on how to use the debugger or maybe a refresher coarse try THIS[www.yoyogames.com] blog from YOYO
Editat ultima dată de The Winter Bud; 29 ian. 2019 la 6:01
The debugger is a pretty good tool, but in this case, I'm sorry to report it did not yeild any new information to me. I points out that it's running into a problem with the object trying to run a varible that isn't set for a script that the object shouldent be running in the first place. and it's always the script at the top of my list of scripts.

In the create event I have:
state = scr_nme_idle_state;

In the step event I have:
script_execute(state);

Yet it keeps trying to run a different script. I don't understand what I did wrong here, but I'm clearly not getting something right.

-Thanks Winter Bud!
Object Step event:
///Run_the_current_state event_inherited(); // <-- THIS RIGHT HERE script_execute(state);
This leads me to think otherwise. Somewhere in the chain of parents the state is being changed.

Maybe you might want to run teh parent's script after the state script
///Run_the_current_state script_execute(state); event_inherited();
Editat ultima dată de The Winter Bud; 29 ian. 2019 la 23:11
in the long run, assigning a value to the variable 'dir' in the create event somewhere along the chain should solve your problem. Even if you figure out what is changing the state, you will still have to deal with the problem of when you run the script ( gml_Script_scr_get_face ) you will get this same error
Editat ultima dată de The Winter Bud; 29 ian. 2019 la 23:09
unfortunately running the parent script after the state script resulted in the same problem, but I think you're on to something with this, I'm looking more into it.

As for the assigning value to the "dir" varible, the object shouldent be running the script calling for the "dir" variable in the first place. It shouldent be running the script scr_get_face either. Those scripts are more for the player object so they have quite a few more varibles after "dir" that the enemy object just won't have. This stubborn thing just needs to use the script I tell it to use!

But yes, this enemy object DOES have the same parent as the player object, and the player object ALSO has a "state" varible. I thought if I changed the name of the varible in the enemy that it would fix the problem (instead of "state" I called the varible "nmestate" in the enemy object") but I was wrong, it dosent seem to make a difference.

As it stands, both the player and the enemy object are both the children of "obj_lifeform", but the parent object doesent have a "state" varible. I dunno, like I said, I'm looking into this now, though we havent quite solved the problem yet, I feel like you've given me a good lead. If anything I said so far give you in idea on what might be going on please let me know! Otherwise, thanks for your time.
Zappy 30 ian. 2019 la 12:23 
To determine if the issue is with the variable or with script_execute(scr,...) (or something else), what happens if you directly use...?
script_execute(scr_nme_idle_state);

Additionally, what does the "error" say if you put the following within the create event of a used object and then run the game?
//Debugging - Show an error containing the hardcoded values for two script resources show_error("DEBUGGING: SCRIPT RESOURCE VALUES: scr_get_face: " + string(scr_get_face) + " scr_nme_idle_state: " + string(scr_nme_idle_state),false);
Editat ultima dată de Zappy; 30 ian. 2019 la 12:24
<snip>

Using the debugger is your only hope here. Put a break point above the script_execute(state) in teh step event and then step through the code one line at a time if you have to, to see where you are actually chaning the state.

EDIT: again I reiterate that things happen fast at 30/60 times per second. Stopping the game and stepping through it so you can see things one at a time is the easiest way to find your problem.
Editat ultima dată de The Winter Bud; 31 ian. 2019 la 10:54
Some opinion if I may. I think your design is flawed. It abuses the parent/child relationships. Parents are designed to group together similar objects which behave, somewhat, similar. The player and enemy behave differently. They are opposed to each other. However, they may wind up using similar scripts. That does not mean they should share similar behavior mechanisms. Define the state machine for the player and then another for the enemy. They can be a child of a 'mob' sort of speaking or 'unit'. But that parent should not try to run both the player and the enemy. They should act on their own. Enemy can use scripts that the player uses but the state machine should be unique to the each the playerParent and the enemyParent
Issue resolved, skip to bottom for details
To answer in order of posts received:

Zappy- if I use scr_nme_idle_state directly I don't get an error, but the enemy (nme) object dosn't move or do anything anymore which is not what the idle state is set up to do. It's supposed to wander around a set amount of space. It just kinda looks stuck.

as for using the code offered I ran into a problem with it before I could run the game. Maybe there's a "common sense" thing I'm supposed to do with it before running the game but as it stands if I copy/paste it I shows that a string is not closed on the second line. Closing that string presents another error saying an assignment operator is expected


Winter Bud- I'll keep using the debugger for sure, and I don't mind agreeing that my design is VERY much flawed. I'm still trying to learn the ropes of this thing, but I do intend to get better at coding.

I have also stopped my abusive child/parent relationship. With therapy, and time, perhaps we can become a family again. I've taken care to separate them more and give them their own specialized code. I've kinda scrapped what I was doing before and started anew. Not sure if it's the most efficient way to code, but it works.

Thank you to everyone who responded to this post, you're all wonderful people and have been very helpful.

If you there's anything else you think I should know before moving forward with game maker I'll be sure to listen, otherwise I'd be fine saying this problem is resolved.
Zappy 2 febr. 2019 la 22:57 
Postat inițial de MadBearPig:
- as for using the code offered I ran into a problem with it before I could run the game. Maybe there's a "common sense" thing I'm supposed to do with it before running the game but as it stands if I copy/paste it I shows that a string is not closed on the second line. Closing that string presents another error saying an assignment operator is expected -
I didn't test that "debugging" code before posting it here, but I did check the online version of GameMaker: Studio's documentation/manual to make sure that the argument count/order was right. I've tested it now, though, and it works for me, showing an intentional "error" when the game is run.

Is it possible that you had an unclosed quote/string before where you pasted it, or pasted it inside of a closed quote/string (and/or replaced the ending quote of a string with it)?
Editat ultima dată de Zappy; 2 febr. 2019 la 22:58
< >
Se afișează 1-13 din 13 comentarii
Per pagină: 1530 50

Data postării: 28 ian. 2019 la 20:48
Postări: 13