Problem: Event activates/initializes Plugin/Script | Answered: [Yes]

Narsiph

GER/ENG
Member
Joined
Aug 8, 2012
Messages
6
Reaction score
0
First Language
german
Primarily Uses
RMMV
Hya!

Normally i always find what i am looking for and/or get workarounds done yaddayadda. But this time it seems i dont find the correct search-words or i am overlooking something. Thats why i am asking my (probably beginner) question(s)


Question 1
- Start / Foreword
I already have seen some scripts and know that i wont have functions just for now since i dont need specific functions (yet, still i already know how i can implement them oO). I even know how i could make functions compatible...

- Is this correct?
var varName = "String" or Boolean (eq false/true) or Number;
(example: var test = "This is a String"; / var test = true; / var test = 293;

- But
I want to make all the work for events outside of the event. Like "ask if the party is (already) carrying a log" and so on. It is more structured and clean as within the events itself. I already have it working perfectly within the games possibilities. Yet i am not able to find the clue how i can do it within an plugin i want to write that does the work.



- Basically what i have in mind

Code:
// States for the Trees. 0 = Harvestable, 1 = Harvested, 2 = Growing
var tree_1_state = 0;
var tree_2_state = 0;
... and so on.

if(event x is activated) {
 do awesome and cool stuff!
};
else
{
 look for biggest booger in the world!
};


- Question(s) related to "What i have in mind"
Are the variables now always set at the start of (the game/event is activated/just once)?
And how can i tell the inGame event to call for this plugin/script? (Well, basically plugin since i write it outside of the game engine)


Phew, that was a lot and probably a lot of people are shaking their heads "Dude... the solution is right THERE! How could you not see/know that?!" :) But belive me, i searched a lot and dug through a lot of topics to find the solution. I probably oversaw it somewhere. So i hope for your help :3


Stay crunchy.
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,254
Reaction score
1,254
First Language
Spanish
Primarily Uses
RMVXA
if you want to grab an event from the interpreter, you'll have to grab the map; from the map, the events hash; and from the hash, the specific event.
I'm almost sure you can check if an event is running by reading the map object, but I don't remember if it would also let you grab the event itself.

variables accessible from the events are also accessible from the interpreter through the $gameVariables global.
you can't flip it and access code variables from events unless the variables are made readable from the code.
 

Narsiph

GER/ENG
Member
Joined
Aug 8, 2012
Messages
6
Reaction score
0
First Language
german
Primarily Uses
RMMV
if you want to grab an event from the interpreter, you'll have to grab the map; from the map, the events hash; and from the hash, the specific event.
I'm almost sure you can check if an event is running by reading the map object, but I don't remember if it would also let you grab the event itself.

variables accessible from the events are also accessible from the interpreter through the $gameVariables global.
you can't flip it and access code variables from events unless the variables are made readable from the code.
So, if a event is running (player uses 'Action' on the Event) the script i made into a plugin for the rmmv can immediately react like "Oh, player used action on a tree-event, now i do the stuff"?

But what if the script has to check all the time, especially when the tree is set to growing, and change the variables on the fly while the player is not at the map where the respective event is? I mean, i got it already working within the game engine but i want to have it clean and nice not... chaotic ^^


edit:

Code:
if (this.eventName("tree1") || this.eventName(22)) {
change var tree1 = 1, give stuff, say "you killed a tree, great...";
}
else
{
say "Nope!"
}

Sorry, i dont have the correct functions/names n' stuff in my head. But i have a big spreadsheet i use as reference for all the possibilities.

But is this more or less correct? Does a plugin always run without pause or does it have to get initialized by any means?
 
Last edited:

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,640
First Language
Czech
Primarily Uses
RMMV
Yes, a plugin can do that. But...
The default MV code is structured in a way that every frame if you press the action button, the game gets your on map coordinates and checks if there is an event nearby. If there is, it gets fired.
Therefore with any potential checks regarding event identity you're wasting time.

So instead of
Code:
function triggerEvent() {
 if (event x is activated) {
 do something}
}
it is much better to have this:
Code:
function triggerEvent() {
 do something
}
and at the beginning of the event page have this script command:
triggerEvent();

The difference between the first and second is simple. The first would need to be a function with a check every frame. Have 20 of them or even 30 of them and your game will slow down. Not lag. Slow down. The reason for that is, requestAnimationFrame is a synchronous function and until it resolves a new frame will NOT be fired. Which is why you need to limit functions that check every frame or trigger every frame to a minimum.
In the second version you have the event check already covered by the engine, therefore you don't need to fire it every frame to check if it's valid.

But of course it is entirely possible. However, it won't make your code clean,since it's just moving code from one area to the other.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,433
Reaction score
7,712
First Language
German
Primarily Uses
RMMV
while the player is not at the map where the respective event is?
That is your biggest problem, because those events do not exist.

Events are parts of map data, and only the current map is loaded into memory - for a lot of reasons including computer capacity.
An event that is not on the current map (exception common events) does not exist for the engine and can't be handled in any way.

And no, changing the engine to always load all events is a very bad idea.

You need to change your approach entirely and only have the event changed if the player enters the map, you can not update it while the player is else where.
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,254
Reaction score
1,254
First Language
Spanish
Primarily Uses
RMVXA
But what if the script has to check all the time, especially when the tree is set to growing, and change the variables on the fly while the player is not at the map where the respective event is?
if you mean to keep tabs on things happening on different maps, you need a global manager.
something that will process everything separately on one end, and at the other end have events that would ping that process only when they're active, to receive updates on the overall situation.

I've been meaning to make something like that for myself, but haven't totally figured it out yet.
this thread just sparked me some ideas, which I think are the way to go: one master plugin running in the background, and individual events synchronizing themselves with it only when they're active in the current map.

for the "how to" on that global manager, try looking at daylight systems, they usually have a global time keeper, and each map pings that keeper after being loaded to refresh the screen and it's events.
 

Narsiph

GER/ENG
Member
Joined
Aug 8, 2012
Messages
6
Reaction score
0
First Language
german
Primarily Uses
RMMV
Alright, yeah.


I already have global Events for the Time (every 60 frames it adds a minute - you get it, just the basic timer) so i just want to write the code a bit easier which is better outside of the rmmv instead of within (I am just more comfortable using notepad++ instead of clicking, changing, looking variable up and so on)

So technically i could have a general plugin that runs, another plugin that stores the temporary/global data of the specific variables i use in the other plugin and the event just calls for an update when the player enters the map.

Just like... uhm, lemme type this somehow very basicly.

Plugin 1: "I say what status the Tree is. Your status can be 0 = harvestalbe, 1 = cut down, 2 = regrowing"
Plugin 2: "I store all the variables. You have 20 trees! I will update them once they ask me!"
Player comes on map with 3 Trees: "Event 1, 2 and 3: "Hey Database. What is our status? We update it now. Thank you"

Am i correct on that idea? That should work since i could let the script check its status every 10 seconds, or on a specific action (entering a map) etc.
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,254
Reaction score
1,254
First Language
Spanish
Primarily Uses
RMVXA
Plugin 1: "I say what status the Tree is. Your status can be 0 = harvestalbe, 1 = cut down, 2 = regrowing"
all trees are *always* regrowing.
that's like counting seconds in the timer,... it always happens.
they won't grow *more* after they're *harvestable*, and they won't be *harvestable* if they're *cut*

that's your first optimization right there.... you don't need 3 separate states if you can make one of them take two values.

I used that logic to control respawning enemies.
after battle, a self-switch is triggered, and the event goes into respawn time.
when the timer reaches 0, the self-switch is reset, and we're back at the beginning.
*that* is the system I didn't expand, because I didn't know how, which I'm now learning how. :D
 

Narsiph

GER/ENG
Member
Joined
Aug 8, 2012
Messages
6
Reaction score
0
First Language
german
Primarily Uses
RMMV
Interesting. Well, you give me ideas ^^

But i can use the regrow state for the seasons which can affect a trees growth as far as i know. Or have different effects on quality of the wood you get when you cut it down and so on. Currently i just work on implementing all the basic stuff for the game. But yeah, i think i will figure out how i can work with a database and the events asking for updates.

Or basically i cann just say "Check every 10 Seconds if there is an event on the map where the player is, if there is an event, update the events or do nothing"

Gosh i tell ya, the feeling of happyness thinking of how i will figure out coding/scripting is crazy ^^ Plus i gonna buy new beard-soap/shampoo today! Woohoow!
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,254
Reaction score
1,254
First Language
Spanish
Primarily Uses
RMVXA
But i can use the regrow state for the seasons which can affect a trees growth as far as i know
Winter: Growth = 0
Spring: Growth = 2
Summer: Growth = 1
Autumn: Growth = 0
Code:
function grow(){
 (allEvents).growth += Growth
}

function changeSeason() {
 if (season > 3) {season = 0} else {season +=1}
 switch (season){
  case 0
    Growth = 0
  case 1
    Growth = 2
  case 2
    Growth = 1
  case 3
   Growth = 0
  }
}
ping grow() every loop of the timer.
ping changeSeason() every X loops of the timer
you'll have to clamp each event's total growth to a maximum so they don't overflow.

down to the basics, this is nothing more than a counter.
in any counter, once you've reached the maximum, you reset.
code in a condition to spot the maximum, an iterator to repeat the process, and the actual addition.
there's really not much more to it.
 
Last edited:

Narsiph

GER/ENG
Member
Joined
Aug 8, 2012
Messages
6
Reaction score
0
First Language
german
Primarily Uses
RMMV
Ah, one thing that i want to know. When i have created a function:

Code:
(function() {

})();

Like now

(function() {

function grow(){
 (allEvents).growth += Growth
}

// doing directly beneath it the next function
// or do i have to create another "(function(){"?
})();
Currently i just know how to make a function and make it compatible (aliasing) if its changing something in the other functions. How is it with creating my very own function? I seem to not see anything related to that topic for me (But i didnt search now for too long since i tackle one problem after another).

Can i write it as direct as you wrote it? Without (function(){})();?
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,254
Reaction score
1,254
First Language
Spanish
Primarily Uses
RMVXA
that's just an example.... look up the proper syntax, you have the game's own files, and google.
 

Narsiph

GER/ENG
Member
Joined
Aug 8, 2012
Messages
6
Reaction score
0
First Language
german
Primarily Uses
RMMV
that's just an example.... look up the proper syntax, you have the game's own files, and google.
Will definitifely do :) I like learning by doing. For now i am very pleased and know what to do.
Thanks for the help and ideas!

Stay crunchy!
 

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
First Language
English
Primarily Uses
RMMV
Can i write it as direct as you wrote it? Without (function(){})();?
For Google purposes, this is an Immediately Invoked Function Expression (IIFE). You'll find more details by searching, but basically it executes immediately, encapsulates variables to its own scope, and can be anonymous or named.

You can also search for the difference between Function Expression and Function Declaration. I find Mozilla Development Network (MDN) to be a great look-up resource.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,040
Messages
1,018,476
Members
137,824
Latest member
dobratemporal
Top