Jump to content


Photo

Creation code bug?


  • Please log in to reply
6 replies to this topic

#1 RangerX

RangerX

    GMC Member

  • GMC Member
  • 922 posts
  • Version:GM8.1

Posted 21 February 2012 - 04:03 AM

Hello fellow game makers,

I have a sprite I use to create slopes in my platformer game. I wanted to use the less sprites and objects possible so I decided to have only one set of objects and simply "mirror" the sprites by a local variable when I need that slope the other way. This works wonderfully in GM8 but when I port my game in GM HTML5, it doesn't work anymore. I currently can't find an explanation.

In the creation code of the instance of my slope object I have:

Cimage_xscale=-1;



In the create event of the object I have:

if(!variable_local_exists("Cimage_xscale"))
then
{
image_xscale=1;
}


Still, when I start the game, the sprite isn't flipped. In GM8 it is flipped. What gives? bug?
  • 0

#2 Mike.Dailly

Mike.Dailly

    Evil YoYo Games Employee

  • Administrators
  • 1497 posts
  • Version:GM:Studio

Posted 21 February 2012 - 08:24 AM

variable_local_exists() (and all those functions like them) are NOT supported. Run your game in Debug mode, and there is a load of messages printed in the console.

To avoid the need for this, you can now "flip" creation code order. Inside the "Global Game Settings / HML5" there is a new "tick box" option to "Change Creation Event Order". Ticking this causes the object create event to run BEFORE the room creation code. This means there should never be any need for variables exists functions.
  • 0

#3 RangerX

RangerX

    GMC Member

  • GMC Member
  • 922 posts
  • Version:GM8.1

Posted 21 February 2012 - 12:25 PM

Ok, I get the message that the function is not supported.
However, I'm not using room creation code, I'm using creation code in the slope object. Ticking the "change creation event order" doesn't solve the problem.
Is there another way I can tell a specific instance of my slope object to flip its sprite? If not, it means there actually is a need for the variable exists functions. :/
  • 0

#4 GameGeisha

GameGeisha

    GameGeisha

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

Posted 21 February 2012 - 02:20 PM

However, I'm not using room creation code, I'm using creation code in the slope object. Ticking the "change creation event order" doesn't solve the problem.
Is there another way I can tell a specific instance of my slope object to flip its sprite? If not, it means there actually is a need for the variable exists functions.

Just ticking "Change creation event order" is only part of the puzzle. You need to change the coding as well.

Creation:
//Default: Flipped
image_xscale = -1;

Instance Creation:
//Override the flip
image_xscale = 1;

No additional variables are needed.

GameGeisha

PS: I assumed that the default course of action is to flip the sprite, and that the instance creation code is responsible for unflipping it. You seem to have a typo in your original code where this is apparently true. If the reverse is what you intended, switch the two pieces around.
  • 0

#5 rwkay

rwkay

    YoYo Games CTO

  • YoYo Games Staff
  • 1415 posts
  • Version:Unknown

Posted 21 February 2012 - 03:34 PM

Of course you can now set the xscale etc in the Instance Properties in the room editor (press M to mirror on X, while hovering over the instance you want to mirror) so you would not need creation code... and you can see what it looks like in the room editor...

Russell
  • 0

#6 icuurd12b42

icuurd12b42

    Self Formed Sentient

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

Posted 21 February 2012 - 09:34 PM

the method has been used by some hard core guys for a long time such as to set properties for the object instance in the room, properties not always related to existing gm variables. for example

obj_Spawner instance create code (id 10001):
m_NumSpawn = 30;
m_AlarmSpawn = room_speed * 60 * 5; //every 5 minutes

obj_Spanner instance create code (id 10002):
m_NumSpawn = 5;
m_AlarmSpawn = room_speed * 30; //every 30 seconds


obj_Spawner create code
alarm[0] = local_variable_get("m_AlarmSpawn"); //defaults to 0 if not set
m_NumSpawn = local_variable_get("m_NumSpawn");

or you can use the variable exists in the first post to set to a default other than 0

alarm0 code
repeat(m_NumSpawn) instance_create(x,y,obj_Zombie);



Now the question is:
Is this broken?

If so, is it possible to re-instate it?
If not in it's current form, I would very much like to see the ability for us to create properties

obj_Spawner create code
property m_AlarmSpawn type double default 0;
property m_NumSpawn type double default 0;
alarm[0] = m_AlarmSpawn; //defaults to 0 if not set


which can be detected and added in that Instance Property window for us to tweak the variables on an instance to instance basis like we used to.
  • 0

#7 RangerX

RangerX

    GMC Member

  • GMC Member
  • 922 posts
  • Version:GM8.1

Posted 21 February 2012 - 11:15 PM

Gotcha. If that's the new way it works, it's awesome. Invert the creation code order and therefore the local variables in the instance are always overriding the object's variables. Me like.
I will try that tonight. :)

This topic is solved on my part but I am curious about icuurd12b42's apparently manual way of handling local variables. Not sure I understand clearly what's written there though.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users