[solved]how do i make all variables return to their initial state?

Discussion in 'Programming' started by Megax60, Mar 17, 2019.

  1. Megax60

    Megax60 Member

    Joined:
    Jun 22, 2017
    Posts:
    67
    i want a script to make all vars of a single object return to what they were in the create event, but with some exceptions like HP, if there is a way to do that without making all variables go to their original state one by one pls tell me
     
  2. VagrantWhaleGames

    VagrantWhaleGames Member

    Joined:
    Jul 10, 2018
    Posts:
    59
    I think you just need to set up two variables. startingVar=10; currentVar=15;
     
  3. Megax60

    Megax60 Member

    Joined:
    Jun 22, 2017
    Posts:
    67
    And do that with each single var?
     
  4. VagrantWhaleGames

    VagrantWhaleGames Member

    Joined:
    Jul 10, 2018
    Posts:
    59
    yeah..

    //example
    playerStrengthStart=1;
    playerStrengthEnd=5;
    playerStrengthCurrent=playerStrengthStart;


    etc
     
  5. Megax60

    Megax60 Member

    Joined:
    Jun 22, 2017
    Posts:
    67
    found a better solution, why not just add a var called me in each object that can be afected

    Create event:
    Code:
    me = obj_player
    and in a script:

    Code:
    with (instance_create(x,y,me)){
        exception = other.exception //hp for example
    }
    
    instance_destroy()
    and adding whatever exception there
     
  6. VagrantWhaleGames

    VagrantWhaleGames Member

    Joined:
    Jul 10, 2018
    Posts:
    59
    yeah sure, seems like it might just depends on the game. Easiest way for me i'd say would still be to set up some variables, maybe even global variables to hold the inital stats, and change the player hp based on that.

    Code:
    ///example
    
    //objGameControl
    //create
    global.playerHp=3
    
    //objPlayer
    //create
    currentHp=global.playerHp;
    then you can change the currentHp of the player etc while always having that initial hp variable to grab from. I guess if you have 10 stats, it gets messy...but I still think it is the easiest way for saving a few initial variables.
     
  7. Dev_M

    Dev_M Member

    Joined:
    Mar 22, 2018
    Posts:
    23

    What if you call perform_event(create_event) and then manually adjust all the exeptions?

    Or copy the variables form create into an alarm, that you call and then adjust all the exeptions...

    Or a third option write a script that has all the create event variables in it going to init, and
    then use exeptions for arguments?

    scr_reinitialize(exeption1, exeption2, etc); Everything thats not mentioned as an argument goes by
    hard coded code to init stage within script...
     

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