Make global variable via event script call?

● ARCHIVED · READ-ONLY
Started by Engr. Adiktuzmiko 4 posts View original ↗
  1. I was just curious if we can make a global variable via the script call event command.

    I have tried this

    Code:
    if ($test == null) {
      console.log("new");
      var $test = new TextCache();
    }

    but everytime I activate the event it shows "new" which means $test is null before it runs

    but if I put this line in a plugin

    Code:
    var $test = null;

    and edit the script call from
    Code:
    var $test = new TextCache();
    into
    Code:
    $test = new TextCache();
    everything works fine, it showed the "new" message only once.

    I also tried putting the var $test = null; in a different event (of course removing the line from the plugin), and it also didnt work. I activated that event first before the main one but it resulted to also showing "new" everytime I activate the main event.

    So it made me think that we cannot define a new global variable via the script call command. Is that the case?
  2. to my understanding that was always part of all makers since RMXP, that the script box is sandboxed - meaning that all data initialized inside it is always lost when the box is closed. you can (as you found out) access data declared outside of it, but any new variables or so defined inside the script box have to be deleted or it might be used to cause other errors...
  3. I see, I dont really think I'd be needing to initialize new globals in it anyway, it just came up as an idea as I was testing some things pertaining to calling prototypes etc, so I decided to ask to be sure.

    Thanks!
  4. This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.