Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

Quick Script to store event's own ID into a variable?

mimi-min

Villager
Xy$
0.00
Hey, sorry for the dumb question but I've looked around and can't seem to find an answer that works.

Basically all I want is to be able to set a variable (#13) to an event's ID when I interact with it.

Right now I'm just using it as a debug, so that when I "talk" to the object it will pop up with text that contains it's ID.

I see that this exists:
Code:
$gameVariables.setValue(var, value);
and I'm assuming I replace "var" with 13, but what do I replace "value" with? I've tried event_id based on another thread, eventId based on some things in the scripting list, and various other variations of capitalization and underscores. All of them cause the game to crash and say "[whatever I was trying] is not defined".

I get the feeling that I'm going about this all wrong.

It seems like it should be easy once I know it, but I don't. :(

Thanks in advance for any help.
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
This one is pretty easy, I'll show you.
JavaScript:
//This is the final snipper you're looking for....
$gameVariables.setValue(13, $dataMap.events[this._eventId].id);

//
//For the value we want to look in the maps data file, we do this with
$dataMap;
// this is an object full of all the maps information, arrays & objects.
//then we want to look through the maps events array we do this with a simple
.events[index];
// now for the events array we want to make sure we get the current event we are interacting with
// so instead of
.events[index];
//we will do
$dataMap.events[this._eventId];
//This bit of code will access the current events object which contains information
//like the x, y and id of the current event, so we want only the id so to access that we simply put .id //after that bit of code.
//We end up with
$dataMap.events[this._eventId].id;

//----------
//So to quickly explain once more this is how it is read
//---------
$dataMap;           // - Accesses maps data object
$dataMap.events[]; // Which will acess the events array for the current map
$dataMap.events[this._eventId]; // Which will access the maps event array but will acess the current event
$dataMap.events[this._eventId].id - //Will access the maps event array and give you the current event id.
 

mimi-min

Villager
Xy$
0.00
Thank you very much for your detailed explanation!

But it seems like $dataMap.events[this._eventId] is returning null (and as a result it's throwing an error when .id is attached). Maybe I misunderstood something?

 

LTN Games

Master Mind
Resource Team
Xy$
0.01
It's working for me.
Put this in a script call and check the console to see what the output is.
JavaScript:
$gameVariables.setValue(13, $dataMap.events[this._eventId].id);
console.log($gameVariables.value(12));
[doublepost=1461548369,1461548150][/doublepost]Sorry, I checked for wrong variable in console do this snippet in a script call instead.
JavaScript:
$gameVariables.setValue(13, $dataMap.events[this._eventId].id);
console.log($gameVariables.value(13));
 

mimi-min

Villager
Xy$
0.00
Do you mean this?

Code:
rpg_managers.js:1618 TypeError: Cannot read property 'id' of null
    at Game_Interpreter.eval (eval at <anonymous> (file:///C:/Users/Mimi/Documents/Games/Project1/js/rpg_objects.js:10437:10), <anonymous>:1:59)
    at Game_Interpreter.command355 (file:///C:/Users/Mimi/Documents/Games/Project1/js/rpg_objects.js:10437:5)
    at Game_Interpreter.executeCommand (file:///C:/Users/Mimi/Documents/Games/Project1/js/rpg_objects.js:8895:34)
    at Game_Interpreter.update (file:///C:/Users/Mimi/Documents/Games/Project1/js/rpg_objects.js:8803:19)
    at Game_Map.updateInterpreter (file:///C:/Users/Mimi/Documents/Games/Project1/js/rpg_objects.js:6080:27)
    at Game_Map.update (file:///C:/Users/Mimi/Documents/Games/Project1/js/rpg_objects.js:5987:14)
    at Scene_Map.updateMain (file:///C:/Users/Mimi/Documents/Games/Project1/js/rpg_scenes.js:417:14)
    at Scene_Map.updateMainMultiply (file:///C:/Users/Mimi/Documents/Games/Project1/js/rpg_scenes.js:409:10)
    at Scene_Map.update (file:///C:/Users/Mimi/Documents/Games/Project1/js/rpg_scenes.js:398:10)
    at Function.SceneManager.updateScene (file:///C:/Users/Mimi/Documents/Games/Project1/js/rpg_managers.js:1673:25)
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
Sorry, it's late here I'm getting ready for sleep. I don't understand why you're getting that error. So, id try on a whole new map, start a new event, set to action button so you can talk to it, then do a script call with this code: Once you playtest and check the console, it should be returning the events Id. If it does not I really don't know, I'll have to put together a small demo tomorrow.
Code:
$gameVariables.setValue(13, $dataMap.events[this._eventId].id);
console.log($gameVariables.value(13));
 
Top