Yanfly's Self Switches & Variables (Lunatic Script Calls)

I'm using Yanfly's Self Switches & Variables plugin: http://www.yanfly.moe/wiki/Self_Switches_&_Variables_(YEP)

And there is some script calls in the "lunatic section" of the help file that I'm trying to use but it doesn't seem to work for me. I'm trying to use the "Control Variable" event command to set a normal variable that I've named to "Temp.Variable B", so that it has the same value as a self variable I use in one of my events.

The eventing can be seen in the picture below:
Y4XFcEJ.png

And this here is a copy-paste directly from the help file under Script Calls (Lunatic):

this.getSelfVariableValue(mapId, eventId, varId)
- Replace mapId with the map ID the event exists on. Replace eventId with
the ID of the event. And replace the varId with the ID of the variable.
This will get the value of that event's self variable.

It looks like it should work to me but "Temp.Variable B" ends up empty (with value "0"), even though the event's self variable is set to a number betweel 1-8.

What am I'm doing wrong I wonder?
Hi there! ^^
Well, if I'm not wrong, I believe there is an error(or a typo) in the yanfly code.
3hSz7dH.png


It says SELF VARIABLE but it's using $gameSelfSwitches...
I don't look at the code so much, so maybe he is using this $gameSelfSwitches with another way... don't know for sure.

BUT!
I want to give you a tip.
In case you are using this inside an event, instead of writing numbers, write this:
Default > this.getSelfVariableValue(mapId, eventId, varId)

New > this.getSelfVariableValue($gameMap._mapId, this._eventId, varId);

1 - $gameMap._mapId > This will return the map id from the current map. So unless you want to take a self variable value from an event of another map, I think this can help you to not do any mistakes, typos, etc.

2 - this._eventId > If you are inside the event in want to obtain the self variable, use this instead of a number. Will return the event Id of the event you are using the script call.

You can use these codes to SET the values too!
this.setSelfVariableValue($gameMap._mapId, this._eventId, varId, value)

-----

this.getSelfVariableValue(3, 2, 41)
This is really a self variable number ID 41? =O
What Eliaquim says can work, but you can also do as provided by the image above, change the red underline
to Variables and see if it works. if it does, its a typo in the plugin.

@Eliaquim nice catch on that code, never imagine that it can be a type if its really true.
@Eliaquim
Hey, than thank you for you reply. I can tell you a bit more what I'm using it for.

I have a self made turn based calender and when the screenshot above is part of a chain of Common Events that play when a new day dawn (or a "new turn" starts).

On the map I have several normal events which the player can control. When the player changes those events they change a Yanfly "Self Variable". The variable set up for this is Variable "41".

What I want to do in this specific Common Event is: to randomize a number between 2-23 (which is the ID's of the events I want to check), and then try to get the value from the SelfVariable used in the the event I just randomized.

It's not the prettiest process you've ever seen I'm sure but it looks like this:

Spoiler: Copy Pasted event code:
Code:
◆Control Variables:#0002 Temp.Variable A = Random 2..24
◆If:Temp.Variable A = 2
  ◆Control Variables:#0003 Temp.Variable B = this.getSelfVariableValue(3, 2, 41)
  ◆
:Else
  ◆If:Temp.Variable A = 3
    ◆Control Variables:#0003 Temp.Variable B = this.getSelfVariableValue(3, 3, 41)
    ◆
  :Else
    ◆If:Temp.Variable A = 4
      ◆Control Variables:#0003 Temp.Variable B = this.getSelfVariableValue(3, 4, 41)
      ◆
    :Else
      ◆If:Temp.Variable A = 4
        ◆Control Variables:#0003 Temp.Variable B = this.getSelfVariableValue(3, 5, 41)
        ◆
      :Else
        ◆If:Temp.Variable A = 4
          ◆Control Variables:#0003 Temp.Variable B = this.getSelfVariableValue(3, 6, 41)
          ◆
        :Else
          ◆If:Temp.Variable A = 4
            ◆Control Variables:#0003 Temp.Variable B = this.getSelfVariableValue(3, 7, 41)
            ◆
          :Else
            ◆If:Temp.Variable A = 4
              ◆Control Variables:#0003 Temp.Variable B = this.getSelfVariableValue(3, 8, 41)
              ◆
            :Else
              ◆If:Temp.Variable A = 4
                ◆Control Variables:#0003 Temp.Variable B = this.getSelfVariableValue(3, 9, 41)
                ◆
              :Else
                ◆If:Temp.Variable A = 4
                  ◆Control Variables:#0003 Temp.Variable B = this.getSelfVariableValue(3, 10, 41)
                  ◆
                :Else
                  ◆If:Temp.Variable A = 4
                    ◆Control Variables:#0003 Temp.Variable B = this.getSelfVariableValue(3, 11, 41)
                    ◆
                  :Else
                    ◆If:Temp.Variable A = 4
                      ◆Control Variables:#0003 Temp.Variable B = this.getSelfVariableValue(3, 12, 41)
                      ◆
                    :Else
                      ◆If:Temp.Variable A = 4
                        ◆Control Variables:#0003 Temp.Variable B = this.getSelfVariableValue(3, 13, 41)
                        ◆
                      :Else
                        ◆If:Temp.Variable A = 4
                          ◆Control Variables:#0003 Temp.Variable B = this.getSelfVariableValue(3, 14, 41)
                          ◆
                        :Else
                          ◆If:Temp.Variable A = 4
                            ◆Control Variables:#0003 Temp.Variable B = this.getSelfVariableValue(3, 15, 41)
                            ◆
                          :Else
                            ◆If:Temp.Variable A = 4
                              ◆Control Variables:#0003 Temp.Variable B = this.getSelfVariableValue(3, 16, 41)
                              ◆
                            :Else
                              ◆If:Temp.Variable A = 4
                                ◆Control Variables:#0003 Temp.Variable B = this.getSelfVariableValue(3, 17, 41)
                                ◆
                              :Else
                                ◆If:Temp.Variable A = 4
                                  ◆Control Variables:#0003 Temp.Variable B = this.getSelfVariableValue(3, 18, 41)
                                  ◆
                                :Else
                                  ◆If:Temp.Variable A = 4
                                    ◆Control Variables:#0003 Temp.Variable B = this.getSelfVariableValue(3, 19, 41)
                                    ◆
                                  :Else
                                    ◆If:Temp.Variable A = 4
                                      ◆Control Variables:#0003 Temp.Variable B = this.getSelfVariableValue(3, 20, 41)
                                      ◆
                                    :Else
                                      ◆If:Temp.Variable A = 4
                                        ◆Control Variables:#0003 Temp.Variable B = this.getSelfVariableValue(3, 21, 41)
                                        ◆
                                      :Else
                                        ◆If:Temp.Variable A = 4
                                          ◆Control Variables:#0003 Temp.Variable B = this.getSelfVariableValue(3, 22, 41)
                                          ◆
                                        :Else
                                          ◆If:Temp.Variable A = 4
                                            ◆Control Variables:#0003 Temp.Variable B = this.getSelfVariableValue(3, 23, 41)
                                            ◆
                                          :Else
                                            ◆If:Temp.Variable A = 4
                                              ◆Control Variables:#0003 Temp.Variable B = this.getSelfVariableValue(3, 24, 41)
                                              ◆
                                            :Else
                                              ◆
                                            :End
                                            ◆
                                          :End
                                          ◆
                                        :End
                                        ◆
                                      :End
                                      ◆
                                    :End
                                    ◆
                                  :End
                                  ◆
                                :End
                                ◆
                              :End
                              ◆
                            :End
                            ◆
                          :End
                          ◆
                        :End
                        ◆
                      :End
                      ◆
                    :End
                    ◆
                  :End
                  ◆
                :End
                ◆
              :End
              ◆
            :End
            ◆
          :End
          ◆
        :End
        ◆
      :End
      ◆
    :End
    ◆
  :End
  ◆
:End

As you can see both in the screenshot in my first post and in the code above I use the "Control Variable" command and set a variable called "Temp.Variable B" (a trash variable I use for various things, hence the name) using yanfly's lunatic code in the script call option.

Example:
Control Variables:#0003 Temp.Variable B = this.getSelfVariableValue(3, 2, 41)

3 refers to the map, 2 is the event on this map and 41 is the number of the Variable I've made into a self variable.

[EDIT: Okay, I figured it out myself. Apparently, I was blind to my own mistake, even though the mistake is evident in the Common Event snippet I provided earlier in this very post. 😅

I somehow missed to change the "If Check" for "Temp.Variable A" after the first two checks so it kept looking for the value "4", leaving out the remaining 5-23 possible outcomes. That was the problem. And Yanfly's script calls actually works like they're supposed to now that I've fixed that.

Oh well. Sometimes (quite often in my case) one just can't see what's right in front of you
.
]

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/yanflys-self-switches-variables-lunatic-script-calls.118809/