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

GM:S 1.4 Can's set local variables

Discussion in 'Programming' started by Minconan, Oct 25, 2018.

  1. Minconan

    Minconan Member

    Joined:
    Oct 25, 2018
    Posts:
    5
    I am still a new,something I still don't know now,
    about variables,i think I did everything I can and read
    everything I can, but it not works.

    report:

    ---------------------------------------------------------------------------------------------------------------------------------------------------

    ############################################################################################
    FATAL ERROR in
    action number 1
    of Step Event0
    for object obj_GasterBlaster:
    Variable obj_GasterBlaster.firecooldown(100161, -2147483648) not set before reading it.
    at gml_Object_obj_GasterBlaster_StepNormalEvent_1 (line 1) - firecooldown += -1
    ############################################################################################
    --------------------------------------------------------------------------------------------
    stack frame is
    gml_Object_obj_GasterBlaster_StepNormalEvent_1 (line 1)


    ------------------------------------------------------------------------------------------------------------------------------------------------

    the code of [gml_Object_obj_GasterBlaster_StepNormalEvent_1] :

    ------------------------------------------------------------------------------------------------------------------------------------------------

    var firecooldown
    var aim_x
    var aim_y
    var aimdirection
    var movedirection
    var destory
    var follow_x
    var follow_y
    var way
    firecooldown = 30
    aim_x = obj_heartmove.x
    aim_y = obj_heartmove.y
    aimdirection = obj_GasterBlaster.image_angle
    movedirection = obj_GasterBlaster.image_angle
    destory = 1
    follow_x = obj_GasterBlaster.x
    follow_y = obj_GasterBlaster.y+25
    way = 0


    ------------------------------------------------------------------------------------------------------------------------------------------------

    and I also trid:

    var firecooldown = 30
    var aim_x = obj_heartmove.x
    var aim_y = obj_heartmove.y
    var aimdirection = obj_GasterBlaster.image_angle
    var movedirection = obj_GasterBlaster.image_angle
    var destory = 1
    var follow_x = obj_GasterBlaster.x
    var follow_y = obj_GasterBlaster.y+25
    var way = 0

    ------------------------------------------------------------------------------------------------------------------------------------------------

    still not working....
    is anything get wrong or GMS version?
     
  2. FredFredrickson

    FredFredrickson Member GMC Elder

    Joined:
    Jun 21, 2016
    Posts:
    118
    When you create the object (in your Create event), use this:

    Code:
    firecooldown = 0
    Then you should be able to change the variable in your Step event.

    That error is basically saying that the object doesn't contain this variable yet - which usually means it needs to be added at Create.
     
  3. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,603
    You have the wrong idea about what var is for. It isn't the universal way to declare variables, it's a specific way to declare variables that won't last between events or script calls. The Manual entry on variable scope makes that very clear.

    When you did this in your Create event:
    Code:
    firecooldown = 30
    That's already enough. This line alone makes an instance variable you can use in later events. Sticking in an extra var on top of that makes a local variable instead, and that loses context as soon as the event is over.
     
    FredFredrickson likes this.
  4. Minconan

    Minconan Member

    Joined:
    Oct 25, 2018
    Posts:
    5
    thx!
     

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