I am making a game with my friend and I'm sorting out some scripts. When I was writing the script for walking, I got the error message below. What did I do wrong?

The error code

Here is my code:

My code

  • \$\begingroup\$ Error messages should be shared as text, not images. This helps improve the search hits your post gets, bringing more eyeballs to it. It also makes your post more accessible to folks who use translator or screen reader software. \$\endgroup\$
    – DMGregory
    Commented Jun 2, 2022 at 21:07

1 Answer 1


When you see an error message like:

Variable [variable_name] not set before reading it.

it means your program is trying to change the value of a variable that doesn't exist. You shall declare a variable in the Create Event so that other object scripts can use and manipulate its value thereafter.

More precisely, you are setting the value of the built-in instance variable x relative to -move_speed. If it were GML Code, it would be equivalent to:

x -= move_speed;

Unfortunately, it seems that move_speed is unknown to the current object. The Key Press Event cannot decrease x by move_speed because it has no idea what move_speed is.

You can fix this by adding a Create Event to the object and including a Assign Variable GML Visual block, in which you define move_speed as a new instance variable that can later be referenced in other blocks or scripts.

  • \$\begingroup\$ I did what you said I added the variable in the create event but this happened ___________________________________________ ERROR in action number 1 of Create Event for object charactertest_obj: Variable charactertest_obj.move_speed(100003, -2147483648) not set before reading it. at gml_Object_charactertest_obj_Create_0 (line 7) - move_speed += 4; gml_Object_charactertest_obj_Create_0 (line 7) \$\endgroup\$ Commented Jun 3, 2022 at 7:12
  • \$\begingroup\$ Can you show the code block where you've assigned the move_speed? \$\endgroup\$
    – Steven
    Commented Jun 3, 2022 at 7:48
  • \$\begingroup\$ @LDLwarrior2 You must assign move_speed the value 4 without enabling the Relative tickbox. Relative means that the value is added to the current variable, otherwise the variable is set to that value. You cannot add values to non-existing variables. \$\endgroup\$
    – liggiorgio
    Commented Jun 3, 2022 at 9:14

You must log in to answer this question.

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