Jump to content


Photo

Effects Of Instance_change


  • This topic is locked This topic is locked
14 replies to this topic

#1 th15

th15

    GMC Member

  • GMC Member
  • 1585 posts
  • Version:Unknown

Posted 26 August 2007 - 09:07 AM

I've been tinkering with this function lately and what's puzzling me is the additional effects it has on the instance. It seems to keep the variables of the original instance but some things do change. Referencing them by their instance id seems to be a little weird. Some built in variables like depth don't seem to carry over. I've been testing it myself but my results have varied pretty wildly so I can't say anything is for sure.

Does anyone else have any data on how the instance_change function behaves? Does it keep all variables? Does it change some variables? Does its instance id stay the same? Can you continue performing functions with it as part of a with statement?
  • 0

Sean 'th15' Chan
site_logo.gif


#2 torigara

torigara

    GMC Member

  • GMC Member
  • 6507 posts

Posted 26 August 2007 - 10:58 AM

My theory is that every variables carry over, except ones those you can set in the object properties window:
- sprite_index
- visible
- solid
- depth
- persistent
- parent
- mask_index
Those porperties seem to set to the default value of the new object. This is only my observation; perhaps only Mark knows the right answer.
  • 1

#3 HaRRiKiRi

HaRRiKiRi

    GMC Member

  • GMC Member
  • 1364 posts

Posted 26 August 2007 - 01:52 PM

I have used this function in my inventory system. And I can say that ID stays the same, and all of the custom variables carry over. I don't know if built-in variable carry over thou.
  • 0

#4 th15

th15

    GMC Member

  • GMC Member
  • 1585 posts
  • Version:Unknown

Posted 26 August 2007 - 02:44 PM

Well, what I've experienced is that the following construction doesn't work:
with (object)
{
instance_change(object,0)
depth = 5
}

The depth of the changed instance defaults to the object's default depth.
  • 0

Sean 'th15' Chan
site_logo.gif


#5 dark_master4

dark_master4

    GMC Member

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

Posted 26 August 2007 - 10:03 PM

From what I've experienced with this command is:
- Keeps EVERYTHING from the original (first) object
- Then overwrites anything with the new object's properties.

Means: If the first object has a varibale tx and another variable ty AND the second (new) object has tx but doesn't have ty, then after the instance change, it will have the (new) tx and the (old) ty. Got it?
  • 0

My YoYoGames Marketplace (Has scripts, shaders and poker chips)


GM:Studio
Desktop Intel i5-4440 3.1ghz, 8gb RAM, NVIDIA GeForce GTX 770 2gb
Laptop AMD Athlon x64 2.1ghz, 4gb RAM, 256mb shared VRAM


#6 ws25

ws25

    Gaming For Geeks

  • New Member
  • 724 posts

Posted 26 August 2007 - 10:15 PM

A lot of confusion can come from the "preform events" part of the function. If this is "true", the new instance will preform its creation event code, if not, all create event code is ignored. I personally never use "change instance", I just create a new instance and destroy the old one.

Helpful? B)
  • 0

#7 dark_master4

dark_master4

    GMC Member

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

Posted 26 August 2007 - 10:19 PM

@ws25: You forgot about the destroy event ::lmao:: if "perform events" is set to true, it will perform that one too.
  • 0

My YoYoGames Marketplace (Has scripts, shaders and poker chips)


GM:Studio
Desktop Intel i5-4440 3.1ghz, 8gb RAM, NVIDIA GeForce GTX 770 2gb
Laptop AMD Athlon x64 2.1ghz, 4gb RAM, 256mb shared VRAM


#8 ws25

ws25

    Gaming For Geeks

  • New Member
  • 724 posts

Posted 26 August 2007 - 11:24 PM

Forgive me, Dark_Master_4

Most people don't use the Destroy Event (except for things that go bang when they touch anything, like missles or bullets.)

B)

Edited by ws25, 26 August 2007 - 11:26 PM.

  • 0

#9 hpapillon

hpapillon

    GMC Member

  • GMC Elder
  • 3020 posts
  • Version:Unknown

Posted 27 August 2007 - 12:42 AM

... or if you have memory cleanup that needs to be done, to dispose of particles, added graphics or sounds... ::lmao::
  • 0
Yes, making games is my day job.
Anime Games
Gaming blog

#10 th15

th15

    GMC Member

  • GMC Member
  • 1585 posts
  • Version:Unknown

Posted 27 August 2007 - 07:00 AM

Well the primary reason I'm using the instance_change function is that I don't want the object to perform it's destroy code. I've never had the second argument set to true in any of my experiments. I'm still looking for a way to reset the depth of an instance after changing it. There doesn't seem to be any way to reference the new instance in the same block of code. My suspicion is that the default values (sprite,depth etc) are reset at the end of the event where the instance is changed.
  • 0

Sean 'th15' Chan
site_logo.gif


#11 dark_master4

dark_master4

    GMC Member

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

Posted 27 August 2007 - 06:40 PM

What you mean? Do you end up with the first (old) object's values or the replacing (new) object's values? You should end up with the new values.
  • 0

My YoYoGames Marketplace (Has scripts, shaders and poker chips)


GM:Studio
Desktop Intel i5-4440 3.1ghz, 8gb RAM, NVIDIA GeForce GTX 770 2gb
Laptop AMD Athlon x64 2.1ghz, 4gb RAM, 256mb shared VRAM


#12 th15

th15

    GMC Member

  • GMC Member
  • 1585 posts
  • Version:Unknown

Posted 27 August 2007 - 07:52 PM

No, I end up with the default values for the object type being imposed.
  • 0

Sean 'th15' Chan
site_logo.gif


#13 TwistyWristy

TwistyWristy

    GMC Member

  • New Member
  • 693 posts

Posted 27 August 2007 - 08:09 PM

My suspicion is that the default values (sprite,depth etc) are reset at the end of the event where the instance is changed.

I think you're right, the default values are reset at the end of the event.
Any other variables you create after the instance_change event remain.

You could copy the depth to a temporary variable and then in the new instances create event, set the depth to the temporary variable.

Or, use a different variable to keep track of the depth and in the end step event or draw event, set the depth to this variable.

TwistyWristy
  • 0

#14 FunkyB

FunkyB

    GMC Member

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

Posted 12 February 2016 - 08:08 PM

instance_change is very weird. In the manual, it does not mention anything about the variables that carry over. However, I use objects as different states for my character (obj_player_run, obj_player_attack, etc.). Before I instance_change into another state, I HAVE to turn off any variables I don't want. Otherwise, those variables would carry over into the next object. For example:

 

speed = 5; //I am moving in my current state.

 

if( press_attack_button ) //But because I don't want to move in the attack state...

{

   speed = 0; //I need to set speed to 0, otherwise "speed = 5" would carry over.  

   instance_change( obj_player_attack, true ); //now I can instance_change

}

 

The same goes for friction and many other variables. At least this is my understanding.


  • 0

#15 TsukaYuriko

TsukaYuriko

    Remember... and never forget

  • Global Moderators
  • 9535 posts
  • Version:GM:Studio

Posted 12 February 2016 - 10:59 PM

Aaaand with that 9 year bump out of the way, we shall let dead things stay dead...


  • 1

yBGBXQa.pngmWOQbeq.png