• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - D&D Object spawner throws "unknown variable" error when assigning instance value to temp variable

S

ShampooDance

Guest
Apologies if this has been covered before, I searched this forum and didn't find any topics covering similar issues.

I have an object that approximates the nearest x/y of the mouse along a set path, which rotates around a center point. I want this object to spawn another object, rotate it so it's facing the same direction as the spawner, and set the new object moving in a fixed direction at a set speed. Right now movement is working fine, but spawning the new object is presenting an issue.

My understanding is that I'll need to assign the new object's instance ID to a temporary variable and then set the rotation and movement parameters using Apply To..., in order to avoid changing the rotation/movement of all instances of this object. Here is the logic that I have currently:

tblocklogic.png

At present, this logic throws the following error upon Left Click:

Code:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Mouse Event for Left Pressed
for object obj_blox_spawner:

Variable obj_tblock.<unknown variable>(100003, -2147483648) not set before reading it.
 at gml_Object_obj_blox_spawner_Mouse_4 (line 34) -            image_angle = block_dir;
    }
############################################################################################
I've tried assigning other names to the temporary variable, and/or initializing the temporary variable prior to the Create Instance command, but neither alleviate the issue. I've compared my implementation to the example given in the manual entry for Create Object Instance and don't see a difference beyond the instructions given after Apply To..., though I'm sure there's something I'm missing.

Any clarification or help anyone is able to provide is much appreciated! GMS2 is my first real attempt at this sort of thing so I'm sure there are a lot of programming best practices that are obvious to knowledgeable folk and totally lost on a novice like myself.
 
Try other.blockdir in the Set Instance Rotation action and at all other occurrences
or add an Assign Variable block directly under Apply To and set blockdir to a value of other.blockdir

edit: or, this:
use other.blockdir in the Set Instance Rotation
and in all other blocks below use image_angle instead of blockdir
 
Last edited:
Top