Obtaining $gameMap event note property?

I can utilise...
Code:
if (~$dataMap.events[id].note.indexOf("")) { }

within a for loop like...
Code:
(var id = 0; id < $dataMap.events.length; id++)

to find a specific event within a map. However, added events (such as spawned events via Galv's plugin) aren't part of $dataMap and this method cannot work.

I've tried various ways for $gameMap...

Code:
$gameMap.events()[id].note.indexOf("")
$gameMap.event(id).note.indexOf("")
$gameMap._events[id].note.indexOf("")

but I'm unsuccessful. Is it possible? I don't fully understand the difference between dataMap and gameMap. I assume dataMap is static data created when the game is loaded, while gameMap is dynamic and changes during gameplay. Is it that gameMap doesn't possess the note box property?
It would depend on how those scripts build an event - what do they base it on, to get the initial settings?

If I wanted to get a note from an event by going through $gameMap, I would do this:
Code:
$gameMap.event(id).event().note.indexOf("")

because a $gameMap.event(id) is the event object in the game, not the event that you've defined in the editor. The Game_Event class has an event() method which gives you back the data that you defined in the editor - this includes the note. So $gameMap.event(id).event() is your event from the editor.

Added events may refer to an existing event in the editor (so the same editor event is used to create multiple on-map events during the game), or a definition set up some other way, which may or may not include notes.
EDIT: Added a "~" at the front and it works. So instead of $gameMap.event(..., I used ~$gameMap.event(... . What does the "~" do?

Based on Galv's thread here https://forums.rpgmakerweb.com/index.php?threads/galvs-event-spawner.61878/
I believe he allowed his spawn events to include the note tag data.

However, I'm testing with a non-spawned event at the moment. "id" is referencing an event that exists in the map editor (or defined in the editor I supposed I should say). It seems to be able to process the code, but I'm getting a false when I think I should get a true.

The note tag part is: note.indexOf("<Puz:StepSwitch>") and the event I'm referencing has a note of <Puz:StepSwitch>.
But the code processes as if it's a false.
I have no idea what the ~ does. If you don't know what it does, why did you add it? What made you think it would do anything?

Try this:
Code:
/<Puz:StepSwitch>/i.exec($gameMap.event(id).event().note)

in a conditional branch, and it should return true if the source event has that in its note box.
@Shaz It worked. As for the ~, long ago somewhere on this forum I learned to scan event notes on a map via
Code:
if (~$dataMap.events[id].note.indexOf("")) { }

I can't remember if the ~ was explained or not.
~= means "contains", but only in RGSS. It does not do the same thing in Javascript.

In Javascript, my trusty book tells me it is the bitwise not operator. So definitely not something you should be using in a string search. I suggest you remove it, and that adding it may have caused it to appear to work because you might have changed something else that was the real problem at the same time.

Actually, if your previous test wasn't working (was returning false), adding ~ to the start would simply have negated that result. So it wasn't returning true because it was finding the text in the note - it was returning true because it WASN'T finding the text in the note, but you were telling it to give you the opposite result.
Okay. I'd try using your suggestion above. Just one question: How can I make the note tag wording in
Code:
/<Puz:StepSwitch>/i.exec($gameMap.event(id).event().note)

be able to accept different entries? Such as <Puz:1>, <Puz:2>, etc. With my previous method I was doing:
Code:
note.indexOf("<"+numA+numB+">")

to vary what type of note tag the script looks for. I'm unable to immediately test the same method with your suggestion at the moment. Though I'm assuming it wouldn't work.
I'm not sure if this will work, but give this a go:

Code:
/#{"<"+numA+numB+">"}/i.exec(...etc...)

I have only seen others use the #{...} syntax - haven't used it myself. I think that's how it works.

So
Code:
/#{"<Puz:"+num+">"}

If you want to GET the number from <Puz:?> I'm not sure what you'd need to do for that.
I've tried
Code:
if (/#{"<"+numA+numB+">"}/i.exec(...etc...)

to no avail. I was trying to find "<Guest:Test>". Ideally I'd want to utilise numbers in those tags though.

Luckily, at the moment, I've reverted to the old method
Code:
$gameMap.event(id).event().note.indexOf("<"+numA+numB+">")

And it works... weirdly. In my test I'm seeking out <Guest:2>, but an event with <Guest:4> gets targeted.

Interestingly, when I include the "~" symbol, <Guest:2> correctly gets targeted. Not sure why, but I'm still investigating.
As I said above, it's not that it's detecting the correct text - it's that it's NOT detecting the correct text, but you're telling it, with the ~, to give you the opposite of the actual result.

So you could have a number of situations where it's NOT detecting that text, but it will tell you it does. Even on an event that DOES have that text, if the command is not set up correctly and gives you a false result, your ~ is turning it into true. It doesn't mean it's detecting the text. If it were correctly detecting it, then the ~ would be telling it to return false when it gets a true result.
Yea, I understood that. Under that reasoning was why I said I was confused. I've tested further and I believe the opposite is actually in effect, at least for me. Without the "~" it's returning the opposite result.

So back to the example I used:

1) The game would create two new events (via Galv's pluggin): ID# 218 (<Guest:2>) and ID#219 (<Guest:4>).

2) I then run a code which includes defining numA and numB as "Guest:" and "2".

3) Then the code also runs:
Code:
for (var id = $gameMap.events().length; id > 0; id--) {

if ($gameMap.event(id).event().note.indexOf("<"+numA+numB+">")) {

Galv.SPAWN.unspawn($gameMap.event(id)); console.log(id); break;

}
}

3) The first event, ID# 219 (<Guest:4>) is checked and despawned. With the "~", it skips ID #219, checks #218 and despawns that one (since that note tag matches, apparently).

*) Without the "~", I changed the notetag of event #219 to <Guest:2>. This time the code skips both ID #219 and #218 (both have <Guest:2>) and attempts to despawn event ID #217.

Is it possible to edit the function of "~" via a script? I hope I'm not making a big misunderstanding.

Original thread: https://forums.rpgmakerweb.com/threads/obtaining-gamemap-event-note-property.86241/