An Array in a script call?

● ARCHIVED · READ-ONLY
Started by kartacha 10 posts View original ↗
  1. TLDR: How can I define, call and overall use array in script calls?

    Explanations: Lately I have been experimenting with some spikes puzzles and global control for the spikes. Puzzles look simple - you have a controller event (button) and spike events (multiple for each button). When the button is pressed it brings down the spikes so that the player can pass. Then it turns into a parallel event that counts N frames in the background and after the frame window ends the spikes go back up. Here is a screenshot of the first page of the controller event:

    upload_2018-7-22_21-6-28.png

    The second one is the same but it basically turns off each individual Self Switch A. However, in order to turn these on I need to call the command 3 times and manually type all the IDs all of the spikes events. What I want to do instead I imagine like that (I just need the right "wording" for it):

    Code:
    mapid = $gameMap.mapId();
    sswitch = "A";
    ss = true;
    //Define some array with manually chosen event IDs
    //Define variable l with the number of elements that the array contains
    for (var i = 0; i <= l; ++i)
    {var key = [mapid, array[i], sswitch];
    $gameSelfSwitches.setValue(key, ss);}

    Could you help me do that? Also, if there if there is some nifty way to make a code that checks all events notes for some special tag like "<Spikes1>", "<Spikes2>" and take all event IDs for the events tagged with the specific note.

    If you ask why don't I just use global switch for this then...you have a point here! I cannot do that though. I implemented in my game "restart puzzle on command" system. Press R to restart the puzzle. It brings the player to the entrance of the puzzle and restarts all self switch A (to OFF) of all events in the map. So I would like to have these restarted when the player presses R as well. I am also a little sceptic about how the game would react if the player leaves the screen before the parrallel event could have restarted the spikes for example.
    I use global switches only for events that must not be affected by the restart (like taking a special item, learning a crucial skill or having perma block on some of your paths) and self switches for all else.
  2. 1) your Problem is not the array, but that the script call is sandboxed and all its local data erased on closing the call.
    If you use a mini-plugin to define an error with global access, that array can take and hold data from script böses.
    2) search the help file for the meta command
  3. I understood exactly nothing. Sorry Andar, I am really not sure what are you implying.
  4. Sandboxing in a programming environments means that no data in the sandbox must ever leave it, and that all data i side it is deleted when the sandbox itself ends.
    So if you define an array or anything else inside a script command, that data is deleted as soon as the script command ends. If you use another script command later (even directly after the other script command), that means that the second script box has no access to data defined in the first one.

    That is that causes problems with storing complex data - and the solution is to use a plugin to get ways to store that data outside the sandbox.
    And that is also why the data in mapid, sswitch and so on from your first script box no longer exists when you try to use it in the second script command.
    If you combine the command into a single script box then the array key would work exactly as defined.


    As for the second part - meta is the Name of a JavaScript function that is described in the editors help file and that does what you asked as the second question. Just open the help file and search for it to learn how it is used to read notetags.
  5. So how these two script calls that follow eachother work? Should not the ss and the sswitch stop being defined after the first script call ends?
    And also, you are sure that I cannot use array of any type in the script call even if it is just in a single script call? Even and array that I need to set manually for each script will do. It will be better than writting dozens and dozens of instances of these two lines:
    Code:
    var key = [mapid, id, sswitch];
    $gameSelfSwitches.setValue(key, ss);
    Also, I will give the JS stuff a chance but I will likely fail as I do not know anything about scripting at all.

    Also, a side question - what language these script calls are on? It looks somewhat like JS but is it that? Should not it be Ruby?
  6. As I said you can use an array like your code in a single script box.
    And MV switched to JavaScript because it creates HTML5 games for multi system deployment. Ruby was used from RMXP to RMVXA, but couldn't be used for other system deployment.
  7. Yay, I read some array tutorials and it seems that I will end up using this code at least for my prototype and early versions and switch to the more complex meta plugin if I end up needing it for the more complex puzzles later. This one will save me a lot headache I guess and it is easily customizable for individual cases.
    Do you see any problems with the logic? It will read and process all the elements in the array, right? At first test it does not seem to miss anything but you never know.

    Code:
    mapid = $gameMap.mapId();
    sswitch = "A";
    ss = true;
    var obj = [20, 21];
    var l = obj.length;
    for (i = 0; i < l; i++) {
    var key = [mapid, obj[i], sswitch];
    $gameSelfSwitches.setValue(key, ss);}
  8. You should explicitly declare all variables:
    Code:
    var sswitch = "A";
    Instead of:
    Code:
    sswitch = "A";

    Besides that it looks fine
  9. They worked even without this and I guess it is because of some auto correct functions of the program. I will include these though. Safety first. Thank you guys!
  10. 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.