Jump to content


Photo

Code Is Applying To First Instance Only


  • Please log in to reply
16 replies to this topic

#1 sumbodyshero

sumbodyshero

    GMC Member

  • GMC Member
  • 43 posts
  • Version:Unknown

Posted 13 June 2012 - 05:25 PM

Hey, guys. I've wrestled with this for two hours. I have multiple instances of the same object, yet the instance variables are applying to only the first instance in the room.

Has anyone else encountered this? Does anyone know of a solution?

Edited by sumbodyshero, 16 June 2012 - 01:41 PM.

  • 0

#2 ZyklonMiraj

ZyklonMiraj

    GMC Member

  • GMC Member
  • 136 posts
  • Version:Unknown

Posted 13 June 2012 - 05:47 PM

is it being triggered from another object?
  • 0

#3 sumbodyshero

sumbodyshero

    GMC Member

  • GMC Member
  • 43 posts
  • Version:Unknown

Posted 13 June 2012 - 06:26 PM

is it being triggered from another object?


Yes and no: it contains physics_test_overlap with the x and y being that of a separate object called "trigger" which then starts off all of the code (except for the declaring of variables, which is done in the creation event as instance variables). It is not created by another object: just placed in the room editor (3 instances of it).
  • 0

#4 Mike.Dailly

Mike.Dailly

    Evil YoYo Games Employee

  • Administrators
  • 1497 posts
  • Version:GM:Studio

Posted 13 June 2012 - 06:52 PM

If it's in the room, right click on it and add some "Creation Code". This is unique to THAT instance.

This is run AFTER the instance's create event.
  • 0

#5 sumbodyshero

sumbodyshero

    GMC Member

  • GMC Member
  • 43 posts
  • Version:Unknown

Posted 13 June 2012 - 10:09 PM

If it's in the room, right click on it and add some "Creation Code". This is unique to THAT instance.

This is run AFTER the instance's create event.


The problem with that is that these values need to constantly be checked (they are in the step event).

I really don't understand why I am having this problem. From what I've read and understand, instance variables should apply to each instance individually. Am I wrong about that?
  • 0

#6 BorisE

BorisE

    GMC Member

  • New Member
  • 200 posts

Posted 14 June 2012 - 07:29 AM

Please clarify, are you using the <object>.<variable> syntax because if so that stopped working in GM:HTML5 and as far as I know it is not going to be fixed, if you want to affect all instances of an object you need "with".
  • 0

#7 sumbodyshero

sumbodyshero

    GMC Member

  • GMC Member
  • 43 posts
  • Version:Unknown

Posted 14 June 2012 - 02:10 PM

Please clarify, are you using the <object>.<variable> syntax because if so that stopped working in GM:HTML5 and as far as I know it is not going to be fixed, if you want to affect all instances of an object you need "with".


Thanks for your reply.

I am just using instance variables (no "var") inside of "step --> run code (not script)", but the variables are acting like global instances rather than separate ones for each instance. Is this a common problem? I basically have to create separate objects and rename each variable, putting a "2" or "3" after it.
  • 0

#8 cotycrg

cotycrg

    GMC Member

  • GMC Member
  • 851 posts
  • Version:GM:Studio

Posted 15 June 2012 - 12:53 AM

Please clarify, are you using the <object>.<variable> syntax because if so that stopped working in GM:HTML5 and as far as I know it is not going to be fixed, if you want to affect all instances of an object you need "with".

Wait what? I've never had an issue with this. object.variable=2; for example should change the nearest instance's 'variable' to 2, and only that ones. No other instances are accounted for in that syntax. I think the thing with "nearest" instance has changed from HTML5 onward, I don't know how it selects which now.. but it was never meant to change all instances of that object's variable..that is what "with" is for anyways.
  • 0

#9 2Dcube

2Dcube

    Programming sucks

  • GMC Member
  • 704 posts
  • Version:GM:Studio

Posted 15 June 2012 - 02:29 AM

Let's say you have 3 instances in your room of "objectX".

objectX.variable = 2
will set variable to 2 only for the first instance that was created (or the last if it's changed since 8.1)*

with(objectX)
{
  variable = 2
}
will set variable to 2 for all instances of objectX

*) if I remember correctly
  • 0

#10 Mike.Dailly

Mike.Dailly

    Evil YoYo Games Employee

  • Administrators
  • 1497 posts
  • Version:GM:Studio

Posted 15 June 2012 - 07:09 AM

The problem with that is that these values need to constantly be checked (they are in the step event).
I really don't understand why I am having this problem. From what I've read and understand, instance variables should apply to each instance individually. Am I wrong about that?


What?!?!? The create event allows you to setup values needed by the instance. So inside the create event for an instance if you set my_value=10, then this variable is there for checking in the step loop. They don't "go away" after the creation code is run.

You can use the Create event to set default values, then the creation code to override them.
  • 0

#11 BorisE

BorisE

    GMC Member

  • New Member
  • 200 posts

Posted 15 June 2012 - 07:12 AM

Let's say you have 3 instances in your room of "objectX".

objectX.variable = 2
will set variable to 2 only for the first instance that was created (or the last if it's changed since 8.1)*

Well the dot syntax used to set all instances up to at least GM8.0, and I think GM8.1
GM:HTML was inconsistent between Windows and HTML, though I don't know what it does now.
  • 0

#12 sumbodyshero

sumbodyshero

    GMC Member

  • GMC Member
  • 43 posts
  • Version:Unknown

Posted 15 June 2012 - 01:18 PM


The problem with that is that these values need to constantly be checked (they are in the step event).
I really don't understand why I am having this problem. From what I've read and understand, instance variables should apply to each instance individually. Am I wrong about that?


What?!?!? The create event allows you to setup values needed by the instance. So inside the create event for an instance if you set my_value=10, then this variable is there for checking in the step loop. They don't "go away" after the creation code is run.

You can use the Create event to set default values, then the creation code to override them.


But then the step event applies to only the first instance placed in the room. It is not applying to all of them. So maybe I could use a controller object to test objectX.variable? (Which would waste a lot of memory, but I bet there is an "if object in current room" test.)

Edited by sumbodyshero, 15 June 2012 - 01:19 PM.

  • 0

#13 cotycrg

cotycrg

    GMC Member

  • GMC Member
  • 851 posts
  • Version:GM:Studio

Posted 15 June 2012 - 01:24 PM



The problem with that is that these values need to constantly be checked (they are in the step event).
I really don't understand why I am having this problem. From what I've read and understand, instance variables should apply to each instance individually. Am I wrong about that?


What?!?!? The create event allows you to setup values needed by the instance. So inside the create event for an instance if you set my_value=10, then this variable is there for checking in the step loop. They don't "go away" after the creation code is run.

You can use the Create event to set default values, then the creation code to override them.


But then the step event applies to only the first instance placed in the room. It is not applying to all of them. So maybe I could use a controller object to test objectX.variable? (Which would waste a lot of memory, but I bet there is an "if object in current room" test.)

What....no. The step event will happen for all instances of that object, if you use the step event of that object. Silly thing, you. Read the help file a bit more.
  • -1

#14 sumbodyshero

sumbodyshero

    GMC Member

  • GMC Member
  • 43 posts
  • Version:Unknown

Posted 15 June 2012 - 01:40 PM




The problem with that is that these values need to constantly be checked (they are in the step event).
I really don't understand why I am having this problem. From what I've read and understand, instance variables should apply to each instance individually. Am I wrong about that?


What?!?!? The create event allows you to setup values needed by the instance. So inside the create event for an instance if you set my_value=10, then this variable is there for checking in the step loop. They don't "go away" after the creation code is run.

You can use the Create event to set default values, then the creation code to override them.


But then the step event applies to only the first instance placed in the room. It is not applying to all of them. So maybe I could use a controller object to test objectX.variable? (Which would waste a lot of memory, but I bet there is an "if object in current room" test.)

What....no. The step event will happen for all instances of that object, if you use the step event of that object. Silly thing, you. Read the help file a bit more.


Obviously. I know that that *should* happen, but it is simply not.

Edited by sumbodyshero, 15 June 2012 - 01:42 PM.

  • 0

#15 cotycrg

cotycrg

    GMC Member

  • GMC Member
  • 851 posts
  • Version:GM:Studio

Posted 15 June 2012 - 01:49 PM

In which case you're doing something seriously wrong. Feel free to PM me a gmz file and I can help you out.
  • 1

#16 sumbodyshero

sumbodyshero

    GMC Member

  • GMC Member
  • 43 posts
  • Version:Unknown

Posted 15 June 2012 - 02:31 PM

If you can tell me what I am doing wrong, I will be your best friend.

Edited by sumbodyshero, 16 June 2012 - 01:42 PM.

  • 0

#17 cotycrg

cotycrg

    GMC Member

  • GMC Member
  • 851 posts
  • Version:GM:Studio

Posted 15 June 2012 - 04:19 PM

I honestly have zero idea what you are trying to accomplish in the first post. And the syntax is just awful.
  • -1




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users