1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

Drag And Drop always: 'variable not set'

Discussion in 'Programming' started by Karol Bakk, Nov 7, 2019.

  1. Karol Bakk

    Karol Bakk Member

    Joined:
    Oct 27, 2019
    Posts:
    3
    screenshot.png

    Hello! Always i have this problem. I don't know what to do to repair this bug. Please help.
     
  2. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,426
    Is your code really "global.global.variablename"? You don't need that second "global" if so
     
  3. Karol Bakk

    Karol Bakk Member

    Joined:
    Oct 27, 2019
    Posts:
    3
    really? but even with normal variables (not global) if you know what i mean
     
  4. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,426
    Show your code then, I'm going off this line in your screenshot
    upload_2019-11-7_16-21-57.png
     
  5. Karol Bakk

    Karol Bakk Member

    Joined:
    Oct 27, 2019
    Posts:
    3
    friend, i fixed this problem with THIS global variable but i have another problem with other global variable :/ (btw im huuge newbie)

    ___________________________________________
    ############################################################################################
    FATAL ERROR in
    action number 1
    of Create Event
    for object przejsciemuzyka01:

    global variable name 'MUZYKA01' index (100004) not set before reading it.
    at gml_Object_przejsciemuzyka01_Create_0 (line 5) - if(global.MUZYKA01 == 1)
    ############################################################################################
    --------------------------------------------------------------------------------------------
    stack frame is
    gml_Object_przejsciemuzyka01_Create_0 (line 5)
     
  6. rIKmAN

    rIKmAN Member

    Joined:
    Sep 6, 2016
    Posts:
    4,646
    You need to create / initialise the variable before you can try and access it, this is why the error message says "not set before reading it".
    You can't check if something equals 1 if it doesn't exist yet.

    Create Event:
    Code:
    // create / initalise the variable
    global.MUZYKA01 = 1;
    
    // check if it equals 1
    if(global.MUZYKA01 == 1)
    {
        // do something
    }
    
     
  7. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    6,977
    This is the same error as before, ie: the variable you are trying to reference has not yet been created. In general, you want to have ALL your global variables in a script, and then call this script in a room at the very start of the game. What I generally do is have an "initialisation" room, which is a room that has a single object in it, and in that object Create Event I set up all the cameras, global variables, buffers, etc... for the whole game and then go to the next room which is when my game ACTUALLY starts. This ensures that everything is set up before any other object needs to access it.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice