Script to transfer notetag data to variables and switches

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,668
First Language
German
Primarily Uses
RMMV
Idea:
Sometimes a complex event might need additional data that can't be stored in the database directly. In the case of scripts that is where notetags were often used, but there currently is no way to access notetags from events.
This script should give the developer that option by using a script call that transfers notetag data into switches and variables.

Examples:
A common event might load an enemy number from a map notetag and disable random encounters after that number of battles
A map event needs to check if the main actor has the gender-tag <male> or <female> in the notebox before proceeding
An event's battleprocessing needs to check if the selected troop (by variable) has special effects



Details:
It should be a number of script calls that check and return different values to switches and/or variables.
Some of them will require a specific format, others should enable checks for any notetag to allow checking for notetags that are for different scripts.

The script calls should enable checking different object type, either by giving an object itself or by using different functions for different objects.

Object type: Read data from

Map: Map Notebox (active map or map ID)
Map Event: comment box (on active page only)
Tileset: Tileset Notebox (active tileset or tileset ID)
Class, Skill, Item, Weapon, Armor, State: corresponding notebox by ID
Actor: Actor notebox by ID
Actor special: combined noteboxes of actor plus equipments by actor ID
Enemy: Enemy notebox by ID
Troop: comment box (on first troop event only, by ID)



Notebox format:
This format might be rewritten if the scripter has better ideas.

<custom values>Maplevel: 7Mapencounters: 20Surprise: OFFCrafting: OFF</custom values>
Error-check:
In all cases, the function should return true if the notetag exists and false if not - this can be stored in a switch for later checks.

In the case of custom values, the data received if the notetag exists should be stored inside the switch/variable whose ID was given.

Function names are examples to describe what should happen, may be redefined by scripter if needed - for example if the functions need to be split on different functions or if additional data needs to be given (tag for object kind and object-ID for example)



1) Check for general notetag (independent, might work with any notetag from any script):
$game_switches[check-ID]=notetag_present(object, 'notetagstring')

Examples:
notetag_present(currentmap,'<lock parallax x>')
When using Yanfly's parallax-lock script, this would detect if the map has that notetag to change other options in addition to yanfly's script function.


2) Check for custom switch value:
$game_switches[check-ID]=custom_switch(object, 'namestring', Switch-ID)

Example:
$game_switches[99]=custom_switch($game_party.members[0], 'Crafting', 100)
Stores into switch ID 100 the result of the custom value 'Crafting' to allow or forbid accessing the crafting event depending on who leads the party (if the custom values are places in the actor notetags)



3) Check for custom variable value:
$game_switches[check-ID]=custom_variable(object, 'namestring', Variable-ID)

Example:
$game_switches[99]=custom_variable(currentmap, 'Mapencounters', 81)
Stores into variable 81 after how many battles the event should do something (if the battles are counted with other commands)



For compatibility reasons I would like the scripter to add completely new functions to the Game interpreter to achieve this.
All examples above (function names, notetag format) might be rewritten if that makes it easier for the scripter.
For example the functions might be rewritten to

custom_variable:)key, ID, 'namestring', Var-ID)

where key can be something like :actor or :weapon or so and the ID then identifies the exact object.
That might even be better usable by non-scripters who don't know the script names for the game objects.
 
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,959
First Language
English
Primarily Uses
RMMV
This sounds like an interesting idea, but when I was thinking about implementing it there are a couple of concerns:

Checking for a general notetag string: the problem here is that simply searching the notetag for the string will still return true if someone who is using no scripts at all coincidentally decided to write a notetag containing that string. Obviously on the developer end if you're not using scripts you wouldn't be using this one, but one of my jobs as a scripter is to identify the fringe cases where an idea breaks down, and this is one of them.

Secondly, even if you do locate said notetag, what then will be done with it? Sometimes a notetag is defined in a script that performs a bunch of other processing behind the scenes that the developer might not be aware of, so simply setting a variable or switch to a particular value might not work the same way as the original script call(s) did.

Differentiating between objects is another issue, but you already addressed that in your potential rewrite of the call so that's not such a big deal. I think the problem is that so many different scripts use notetags in so many different ways that it would be a bit of a struggle to unify them under a single search-and-set script.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,668
First Language
German
Primarily Uses
RMMV
Checking for a general notetag string: the problem here is that simply searching the notetag for the string will still return true if someone who is using no scripts at all coincidentally decided to write a notetag containing that string.


Secondly, even if you do locate said notetag, what then will be done with it?
1) Basically yes, but you as the developer are responsible for knowing when you did that. For team efforts there has to be at least a minimal talking to each other to prevent that problem, but if a team doesn't talk to each other it'll fail anyway.


2) Of course the notetag still needs the original script to work its original intention - that's one reason why I pointed out to compatibility and independent functions.


This is only to add events when the other script is required by it's notetags to do something.


Imagine a common event that changes background music for maps with a special parallax lock (where player movement might be different for example)


Or a troop event that checks if a battlesprite is present and uses a transform to change the enemy picture if not.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,959
First Language
English
Primarily Uses
RMMV
Is your suggestion, then, that all the scripters band together to create a compatible script that assigns true/false and numerical values from other scripts to switches/variables or am I completely misunderstanding you?
 
Last edited by a moderator:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,668
First Language
German
Primarily Uses
RMMV
You are completely misunderstanding. The intention of this script is to read data, no matter what other function that data has, and no matter who required that other data.


ONLY the game developer should ever be concerned about what uses he puts to this script, and there should be no need to ever check any compatibility for it.


YOU as the writer of this script should simply ignore all other scripts, no matter if they're present or not. it should never concern you, because you only check if a given string is inside the notebox or not - nothing else.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,959
First Language
English
Primarily Uses
RMMV
Ahh. I got confused by your custom notetag sample, thinking you were proposing a script that not only detects notetags but assigns their values based on what the original script did. Makes a lot more sense now!
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
Don't know if that helps much, but i did a first version for an event tag reader: http://pastebin.com/UVw3ULHB

Regexes can be registered by calling:

IAVRA::EVENT_TAGS.register:)symbol, /regex/)On page setup, the event will read all comments from its current page (joining multiline comments together with LINEBREAK) and apply each registered regex on them. The results are saved in a hash that looks like this:
Code:
{  :symbol => [    [...],    [...]  ]}
Basically, you have the symbol as key pointing to an array of matches. Each match then contains the captured groups.You can get the tags for a given event id by calling:

IAVRA::EVENT_TAGS.get(<event_id>, :symbol)This returns the array of matches or an empty array if the event doesn't contain the tag./edit: Replaced match with scan, because it's both shorter and gets every match instead of just the first.

//edit: Put comments in the script and moved it to pastebin.
 
Last edited by a moderator:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,668
First Language
German
Primarily Uses
RMMV
is anyone working on this?


Because lavra's solution only checks event comments, not database/map notetags...
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
I actually have an updated version on the script listed in my signature (under Event Tag Reader).


The parse_tags method should work for any kind of notetags and can be transfered to other classes. Since actors etc only have one notebox, you don't have to build the comments first, so that part can be skipped.


But since $game_<...> objects aren't created, but loaded, the parsing would have to either be done in DataManager.load_database or the first time the get/get_all method is called.
 
Last edited by a moderator:

Garryl

Villager
Member
Joined
Feb 19, 2015
Messages
25
Reaction score
4
First Language
English
Primarily Uses
This script should enable you to do what you want: http://forums.rpgmakerweb.com/index.php?/topic/40464-notetag-autoloader/

There's an example in there for adding a level attribute to enemies. You can adjust it to taste for anything else (actors, skills, states, even tilesets and maps).

module Garryl::Loader register(CustomMethod.new( RegexConfig.new(/<level:\s*(\d+)\s*>/i, NoteRegexConfig::CAPTURE_INT), LoadGroup.new(LoadGroup::ENEMIES), :notetag_level))endRPG::Enemy attr_accessor :level def notetag_level(capture) @level = capture[0] endend
For your gender example...

 
module Garryl::Loader register(CustomMethod.new( RegexConfig.new(/<(male|female)>/i, NoteRegexConfig::CAPTURE_STRING), LoadGroup.new(LoadGroup::ACTORS), :notetag_gender))endRPG::Actor attr_accessor :gender def notetag_gender(capture) @gender = capture[0].downcase endend...and in your event...$game_variables[x] = $data_actors[1].gender == "female"

...would pick up if you have <female> in the actor's note box.
You'd have to be a little more creative for things like aggregating the note tags of equipment worn. You could do it with features easily enough, though. There's a "special flag" feature code in the default engine that's practically designed for this.

 
module Garryl::Loader register(LoadFeature.new(RegexConf.new(/<legendary>/i), Game_BattlerBase::FEATURE_SPECIAL_FLAG, 12345))endPut <legendary> in a note box of an actor, class, weapon, armor, or state (or enemy), and you can detect if an actor has it (either directly or through equipment or states) via the following in your event...$game_variables[x] = $data_actors[1].special_flag(12345)
No support for reading comments in troop events, unfortunately. You can't as easily check note tags for maps other than the active one, either, since the maps aren't even loaded into memory until you transfer to them, but take a look at the Game_Map.setup method in the default scripts and at what I did with it in my Loader script if you want to load and inspect inactive maps.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,668
First Language
German
Primarily Uses
RMMV
@Garryl:

From what I can see it would work, but it would also require me to register everything I want to check on the script level.

One of the original intentions was to remove the need for scripting access as far as possible, so that the command takes the given string and analyse it on runtime without need for a preregistered regex.

To keep the example: You're defining a regex that can be either <female> or <male> and naming it to call it. My idea was to simply check if any line in a notebox contains <male> while ignoring all other options or other lines in the notebox. After all, depending on the game setting that might not be limited to <male> or <female>, but could also be <robot>, <neuter>, <other> or <grmblpix>...

And it might change the second I decide to add another alien race...

There should be a way to make such a script without preregistering the possible entries, working it just by string analysis alone.
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
I went the same route as Garryl with the need to register regexes and i stil think it's the better way, since there is no set format for notetags. Also, they may contain further attributes or by multi-line. By registering a regex, you can account for all of that. Otherwise you would force the user of the script to write their notetags in a specific format, that might not be flexible enough.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,668
First Language
German
Primarily Uses
RMMV
since there is no set format for notetags.
That is exactly the reason why I don't want to use regex.


Yes, I agree that it requires some thinking from the user to make sure the tags are checked correctly, but I have no problem with that.


And in some cases the required regex would be rather complex while the user does know what he wrote as the notetags...
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
A simple way would be something like this:

Code:
def get_tag(string, tag)	$1 if string =~ /<[ ]*(#{tag})[ ]*>/iendget_tag("     <abc>", "abc")
This returns the matched tag as in
Code:
<(any amount of space)(tag)(any amount of space)>
and can still be extended by providing another regex like this:
Code:
get_tag("     <abc>", /\w{3}/)
 

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,162
Reaction score
822
First Language
Hungarian
Primarily Uses
RMVXA
If you don't want to use regex at all, than there is no need for any complex scripting either.


For example, you can check an actor's note-tag like this during runtime (using your gender example):

$data_actors[actor_id].note.include?("<male>")You can do this with every database objects which got a notebox, assuming you know how to get the object's ID correctly during runtime.
Use it in a conditional branch with the script option.


So, yes, there is a way to read notetag data without much effort already, actually.


You can even modify it during runtime, but the change will be lost after quitting the game, so there is not much point of doing so.


In the case of events and comment commands, it is a bit more complicated, but a small method can be made in the interpreter to read comments from an event easily too.


One thing for sure...


You can not extract the data from a note-tag like a script would do without actual scripting, obviously.


So having a note-tag like "<steal w98 60>" will stay as a string only until you process the regexp methods you need on it.


Effectively this leads to my next question...


What's with all these new scripts making some kind of "note-tag reader" stuffs? I will never get the point of that, I guess.


There is no way that a non-scripter could use that properly, and one who does know scripting will use his/her own methods rather than adding an extra step to process the code...
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,668
First Language
German
Primarily Uses
RMMV
I'm not opposed to regex directly, I just don't want to use extra complexity when there is no need for it, and no one has said so far why I should use a regex for simple tag checking.

For the variable extraction it's of course neccesary to use regex to filter out the correct number...

The include command should handle the parts for 1 & 2, so only the third point is open and need a script - the ability to read data from a custom notetag into a variable.
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
Using only string compares (include?, index, ...), it won't be possible to capture any value from your notetag.


So if you have "Mapencounter: 3", there is no way to get the 3 out of there without using regex.
 
Last edited by a moderator:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,668
First Language
German
Primarily Uses
RMMV
That was clear from the beginning and I have no problem using regex there.

Just to clear some misunderstanding: I have no problems with regex itself, I just don't want to use code (any code) where it isn't neccessary and using regex for 1&2 is excessive in my opinion. And if someone had shown an advantage for those cases, I would have changed my opinion there.
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
How would the script handle a situation, where a notetag is present multiple times? Say, your notebox looks like this:

Code:
Mapencounters: 2Mapencounters: 3
And you call a method like this:
Code:
custom_variable(object, /Mapencounters: (\d+)/, 3)
What value would be stored inside the variable #3? And how would the method act if, if multiple capture groups are specified?
 
Last edited by a moderator:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,668
First Language
German
Primarily Uses
RMMV
First number counts - there should never be such a case of multiple definitions for the custom values. If there is this is a mistake of the developer/script user and it should just made sure that a valid value is given back. And the simplest way for that would be to use the first value.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,849
Messages
1,016,975
Members
137,563
Latest member
cexojow
Top