Object_ID Help

D

DoesOkay

Guest
Hi, first time posting here. The prefix feature doesn't work or I'd have set it to GMS2. I'm developing a fighting game and working on character state machines right now. Primarily these state scripts need to change values of the instance calling them. I've looked through a number of forum posts, the manual, and a couple other sources.

I'm getting this error code: Variable <unknown_object>.mtm(100003, -2147483648) not set before reading it.

I don't know how to make the scripts know what object to check and change variables for. When the match starts, each controller object with a character selected creates a character object and changes it's 'owner' variable (mostly to keep the controllers separate). I can't just obj_character.variable because that would obv effect both players if they chose the same character. Please let me know if there's an easy way to resolve this.
 

kburkhart84

Firehammer Games
You need to somehow have two different things, variables, objects, something. One way is to have each player be a separate object, and just do the different behavior based on which character was chosen. You could also have the two player objects have their ids stored somewhere. Then you can access them separately even if they are the same object. Just use the code that creates the two player instances to also store the IDs of the two players in something, either the controller object, or global variables.
 
D

DoesOkay

Guest
Actually... yeah. I can just make the controller objects behave as the chosen character would, they're all persistent objects so the id wouldn't change ever right?
 

kburkhart84

Firehammer Games
Actually... yeah. I can just make the controller objects behave as the chosen character would, they're all persistent objects so the id wouldn't change ever right?
If the object is a persistent controller object, then yes, the ID would not ever change.
 
D

DoesOkay

Guest
If the object is a persistent controller object, then yes, the ID would not ever change.
Sorry to bother, but is there a way to not have to write out the object name in front of every variable in the scripts? Like can a script check what object called it and then treat each mention of a local variable as that object's local variable? If I have to write it out every time I'll do it but it seems like there has to be an easier way.
 

kburkhart84

Firehammer Games
You need to look up the with() statement in the manual. You can use it to change the scope of the running code. You would use it on the object ID, and then have the call to the script inside the with() statement. The script would then operate as if the object instance itself was calling the script, and therefore would have direct access to the variables without typing the object name in front.
 
D

DoesOkay

Guest
I am going to read the with() section a few more times. This is my first coding language and I'm learning it very quickly, but ADHD makes it all get jumbled up sometimes.

Would it look something like this though, with the first controller object being called oGP0?

Code:
with (oGP0){script_execute(state)
 

kburkhart84

Firehammer Games
I am going to read the with() section a few more times. This is my first coding language and I'm learning it very quickly, but ADHD makes it all get jumbled up sometimes.

Would it look something like this though, with the first controller object being called oGP0?

Code:
with (oGP0){script_execute(state)
Actually, you don't need script_execute for this at all. You can run the script/function just using the name of it. So if the name of the function is "state" then the following code would work.

Code:
with(oGP0)
{
    state();
}
If you are using 2.3+ and state is not the actual name of the function, rather you stored the function name(without parenthesis) into the variable named state, then you would use script_execute(state);. If the function is a method on an object instance, you do it the same way as the above code.
 
D

DoesOkay

Guest
Actually, you don't need script_execute for this at all. You can run the script/function just using the name of it. So if the name of the function is "state" then the following code would work.

Code:
with(oGP0)
{
    state();
}
If you are using 2.3+ and state is not the actual name of the function, rather you stored the function name(without parenthesis) into the variable named state, then you would use script_execute(state);. If the function is a method on an object instance, you do it the same way as the above code.
Thank you so much, I understand how I need to set it up now.
 
Top