I use this code to create a new enemy and preset some values:

It runs in the step event of the player object.

var inst_inst = instance_create_layer(newX, newY, "Instances_Enemies", obj_Asteroid01);     
inst_inst.image_index.image_xscale = 0.1;
inst_inst.speed = 4;

The speed is set correctly but the code scales the image of the player sprite and not the sprite of obj_Asteroid01

Edit after getting the answer

My fault was to trust the autocomplete and the fact, that there were no compile errors.

This is something you need to get used to :)

enter image description here

  • \$\begingroup\$ inst_inst.image_xscale = 0.1; \$\endgroup\$
    – Dmi7ry
    Commented Jan 7, 2019 at 6:02
  • 3
    \$\begingroup\$ @Dmi7ry even simple answers are worth posting as answers, rather than comments. :) \$\endgroup\$
    – DMGregory
    Commented Jan 7, 2019 at 12:08
  • \$\begingroup\$ I don't think image_xscale is a property of image_index. They're both build-in variables for an object. (called inst_inst in your context). maybe it's able to scale the image based on it's current frame. So that's probably that glitchy part you were talking about. \$\endgroup\$
    – Steven
    Commented Jan 7, 2019 at 13:48
  • \$\begingroup\$ Sorry, I just had no time to write the answer. Done now \$\endgroup\$
    – Dmi7ry
    Commented Jan 7, 2019 at 13:56
  • \$\begingroup\$ @Steven You're right. Beginner's mistake. (GameMaker seems to be a great development environment, but it's not C # or Visual Studio.) \$\endgroup\$ Commented Jan 7, 2019 at 15:06

1 Answer 1

inst_inst.image_xscale = 0.1;

image_xscale is a property of an instance. image_index also is a property of an instance. image_xscale is not a property of image_index.

Reason of the result you got is that instances (and any other resources) in GML are represented as IDs. For example, try show_message(obj_Asteroid01) and it will show you a number. So inst_inst.image_index.image_xscale will be interpreted as "get the instance with index inst_inst.image_index and then set image_xscale for this instance".


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .