Mark/Recall Spell

Trying to make Mark and Recall spells like in Elder Scrolls.

For those who don't know, you cast Mark and that marks the spot. Then you cast recall and are teleported to the spot you marked.

The way these spells work is being cast in the menu, and their effect is to trigger a common event.

Here is the event for the Mark spell:
1707843231243.png


I added the thing to show the messages in my attempt to figure out why this doesn't work. I wanted to check if it was even storing the variables at all.

Here is the event for the Recall spell:
1707843380026.png


For some reason, the Mark spell is triggering immediately on game start.
The console is saying that markspell_room is not defined.
When I cast Mark the messages pop up, but only the first line "Mark spell data:". The other lines aren't there at all.
Nothing else happens.

When I cast recall nothing happens at all, except the console again says that markspell_room is not defined. It is though?
1707843578455.png
There's no reason for you to be trying to use script calls for this. This is all done easily using the editor's included event commands.

The console is saying that markspell_room is not defined.
When I cast recall nothing happens at all, except the console again says that markspell_room is not defined. It is though?
The names that you assign to variables are only used internally, for your reference in the editor.

It does not make global variables with those names - the game variables are referenced by their ID, and that's within an internal array. You're trying to reference them in entirely the wrong way.

All your event needs to do is use this:
1707844164306.png


(and there's another for Y, and Map ID of course)

Then your Recall spell does:
1707844250272.png
When I cast recall nothing happens at all, except the console again says that markspell_room is not defined. It is though?
yes actually

when youre using JS to interact with game variables, you cant just call them by name even though the editor shows it by name. markspell_room does not exist in any context you called it in. use $gameVariables.value(x) to retrieve the value of variable x
additionally, the script command is sandboxed - if you define a javascript variable inside a script box, that variable is deleted when the script box is finished and is NOT available in a different scriptbox.

that is also one of the reasons why you should use the regular event commands whenever possible and use script commands only to do something that is not directly available as an event command - and everything for that combo is available in thetwo event commands control variable and transfer player, no need for scripts at all.
For what it’s worth, I have 4 tutorials experimenting with setting and returning to portals that were inspired by Morrowind.

You can find my tutorials on my YouTube page.

If you decide to check them out, I hope they help.
I did this with eventing.

mark.png

recall.png

If you want the casting element, you can set the common events to switch triggers and have the menu spells turn the switch(s) on. Just remember to add SET SWITCH [#] TO OFF at the end of the event.
If you want the casting element, you can set the common events to switch triggers and have the menu spells turn the switch(s) on. Just remember to add SET SWITCH [#] TO OFF at the end of the event.
I'm not sure why all of that would be necessary. Just have the skill/item call the common event from its Effects list.

Just out of curiosity, why does your Recall event use three additional variables, when all you do is set them to the value of your Marked variables and you don't alter them at all before using them?

You could simply use the IDs of the Marked variables in the Transfer Player command.
if you define a javascript variable inside a script box, that variable is deleted when the script box is finished and is NOT available in a different scriptbox
That's not entirely accurate. Here are a few ways that you can define global variables from within a script command:

JavaScript:
// A variable will be global if you declare it without using
// any preceding keywords (i.e. let, const, var):
globalVariable = 1337;

// A variable will be global if you explicitly attach it to the window object:
window.globalVariable = 1337;

// On MZ, you could alternatively use the globalThis object:
globalThis.globalVariable = 1337;

// A better option would probably be to attach the variable
// to an existing global game object:
$gameTemp.globalProperty = 1337;

// or to create your own global object in which to store any
// global variables for your own personal use:
window.Arthran ??= {};
Arthran.globalProperty = 1337;

None of this is super relevant to the OP's question, but I just thought I'd mention it in case someone comes across that statement in a search or something and gets the wrong idea.

Original thread: https://forums.rpgmakerweb.com/threads/mark-recall-spell.165716/