Show picture based on my variables via script call.

I have a lot of weapons in game and want to show a picture based off which is equipped and saved to a variable.
I could do so through a lot of conditional branches but believe it would be easier with a script, if possible.

My goal is:
if WeaponEquip = 1 , Show pic "weapon1"
if WeaponEquip = 2, Show pic "weapon2"
Currently I'm using:


$gameScreen.showPicture(1, "weapon%1".format(this.$gameVariables.value(41)),0, 0, 0, 100, 100, 255, 0);

but this doesn't seem to work. I have looked and found a similar thread (from which I put together this script) but it is for MV while I'm using MZ. Not sure if that matters much or if my script is just defunct.


I have no prior experience with scripting so I simply put together what I reasonably thought would work, but unfortunately it doesn't seem to.
I have a lot of weapons in game and want to show a picture based off which is equipped and saved to a variable.
I could do so through a lot of conditional branches but believe it would be easier with a script, if possible.

My goal is:
if WeaponEquip = 1 , Show pic "weapon1"
if WeaponEquip = 2, Show pic "weapon2"
Currently I'm using:


$gameScreen.showPicture(1, "weapon%1".format(this.$gameVariables.value(41)),0, 0, 0, 100, 100, 255, 0);

but this doesn't seem to work. I have looked and found a similar thread (from which I put together this script) but it is for MV while I'm using MZ. Not sure if that matters much or if my script is just defunct.


I have no prior experience with scripting so I simply put together what I reasonably thought would work, but unfortunately it doesn't seem to.
The reason it's not working is you writing "this.$gameVariables.value(41)". You don't need "this", it's just $gameVariables.value(41).
Oh wow, so simple yet so effective. This fixed the problem and now works as intended, thanks so much.
Quick question, the reference script I was looking at was :

Script: $gameScreen.showPicture(8, 'Map%1'.format(this._mapId), origin, x, y, 100, 100, 255, 0)

So is "this." always in reference to _mapID? just curious going forward.

Thanks again!
So is "this." always in reference to _mapID? just curious going forward.

Thanks again!
this is the object you're running the script from. It changes depending on where you run the script.
As AquaEcho said, the "this" keyword in Javascript refers to the execution context of the code that's running. In the case of the example you gave, "this" is the instance of Game_Interpreter attached to the map, because when an event is running it's a function of the interpreter that handles it.
Okay, thanks for the explanations, this makes more sense now. Thanks again for the help!

Original thread: https://forums.rpgmakerweb.com/threads/show-picture-based-on-my-variables-via-script-call.164884/