I am following along with a guide. I'm trying to reference code from an instance in my room, but whenever I try to run the script I get this error:

ERROR in action number 1 of Create Event for object objSmileyFace:

Variable objHealth.(100004, -2147483648) not set before reading it.

at gml_Object_objSmileyFace_Create_0 (line 4) - objHealth.playerHealth = objHealth.playerHealth + 10;

gml_Object_objSmileyFace_Create_0 (line 4)

It says objHealth is not set, which is not true. What am I doing wrong?

Code screenshot

  • 2
    \$\begingroup\$ "I am following along with a guide" - which guide? Include a link. \$\endgroup\$
    – DMGregory
    Sep 5 '20 at 22:44
  • \$\begingroup\$ A uDemy course created by Aaron Craig called 'Learn To Code by Making Video Games - No Experience Needed!' \$\endgroup\$ Sep 6 '20 at 3:34
  • 1
    \$\begingroup\$ Since users trying to help you won't necessarily have that guide to follow, you should edit your question to walk through the steps you took to get here. With that, we should be able to reproduce the problem in a new project, spot steps that might be missing or incorrect, and test potential solutions. \$\endgroup\$
    – DMGregory
    Sep 6 '20 at 10:11

The objSmileyFace object is likely created before the objHealth exist.

If you're going to the room where these are defined, check the instance layer and see if both objects are present. and if objHealth is called before objSmileyFace. (priority depends on the order in the instance layer)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.