Windows Global test????

Discussion in 'Programming' started by Jaydon, May 31, 2017.

  1. Jaydon

    Jaydon Guest

    I have set this in a script:
    global.point =0;

    and in another script:
    global.point +=5;

    but I cant seem to figure out how to test this variable :(

    I have tried a few things but I just keep getting errors.

    I want to test this variable so that i can delete an instance of an object but can't figure it out.

    Thanks for the help :)
     
  2. Rabid_Ghost

    Rabid_Ghost Guest

    i would just put this in a draw event.

    draw_self()
    draw_text(0,0,global.point)

    this should draw the value of global.point
     
  3. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    2,352
    Code:
    if ( global.point > 100 ) // example...change this to the appropriate condition for your game.
    {
        with ( <put_instance_id_here>  )
        {
             instance_destroy()
        }
    }
    
    Edit: Because it is a global variable you can run this anywhere.

    What exactly have you tried so far and post the code and error messages you are getting, it will be easier to provide more specific help.
     
  4. Jaydon

    Jaydon Guest

    well what I am trying to do is when you move the player over an object it gets destroyed then you get a score point once you get the 25 points the exit will open, i have everything except the point on destroy.
     
    Last edited by a moderator: May 31, 2017
  5. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    2,352
    In the DESTROY Event for the enemy object, put

    Code:
    global.point +=5
    
    If you have many different enemy objects, instead, create an obj_enemy_parent. Make all your enemy objects children of the obj_enemy_parent, then put the DESTROY Event code in the obj_enemy_parent object.

    In the player CREATE Event:
    Code:
    exit_open = false
    
    Then in the player STEP Event put the following check:

    Code:
    if ( global.point >= 25 && !exit_open) // example...change this to the appropriate condition for your game.
    {
        exit_open = true
        // Write the code to open the exit here.
    }
    
     
  6. Jaydon

    Jaydon Guest

    so this is what I have in my mine:
    [​IMG]

    And in the Gate:
    [​IMG]
    not sure if I did this right.
     
  7. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    1,222
    There's a few problems that I can see there. The mine will just constantly add +25 to global.points every step the player is touching it, even though the sprite has changed. So it will quickly add many many many points for just a second of touching. Secondly, why is the open gate code in an alarm? You should have it in the step event.
     
  8. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    2,352
    Also, GameMaker is case-sensitive. So global.point is not the same as global.Point (note the Capital P you used in one piece of code, in the other you used a small p...you need to make the spelling exactly the same for starters).

    After the player collides with the mine, should you be calling instance_destroy()? So that the instance no longer exists and the player will not continuously get 5 points added to their score?

    Will have a better look later, need to go for now.
     

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