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

Stupid Question - can executing a script or function give an instance Object one+ new variables?

Discussion in 'Programming' started by Niall Edwards, Nov 9, 2019 at 1:50 PM.

  1. Niall Edwards

    Niall Edwards Member

    Joined:
    Thursday
    Posts:
    12
    So, can executing a script (or function?) in an instance object in say the Create event or some other event give that instance object one or more new variables? (aside from using event_perform_object trick)?
     
  2. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    2,264
    Yes. Scripts run in the same context as the instance it was called from. So any variables you declare that do not use the keyword "var" will be assigned to the instance that called that script.
     
    Niall Edwards likes this.
  3. Niall Edwards

    Niall Edwards Member

    Joined:
    Thursday
    Posts:
    12
    @IndianaBones , thanks for the quick response. I am already contemplating then shunting in ds_maps within a ds_map within instances... ;)
     
    IndianaBones likes this.
  4. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    2,264
    You're welcome.

    If you didn't know already, you can also use:
    Code:
    with ( instance )
    {
        my_new_map = ds_map_create();
    }
    
    from anywhere in your game. Using with() changes the context to the instance in the () parentheses, so then any code you write / variables you create gets assigned to that instance. ( instance being an instance id )
     
    Niall Edwards likes this.
  5. Niall Edwards

    Niall Edwards Member

    Joined:
    Thursday
    Posts:
    12
    IndianaBones likes this.

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