JavaScript questions that don't deserve their own thread

Arctica

Veteran
Veteran
Joined
Jul 19, 2021
Messages
83
Reaction score
103
First Language
English
Primarily Uses
RMMZ
I stand corrected on both counts.
 

shukrin

Villager
Member
Joined
Sep 2, 2021
Messages
22
Reaction score
2
First Language
English
Primarily Uses
RMMZ
hmm i wonder why the mod moved my thread when i clearly said the author who originally posted it is not responding. I even already posted there, the last comment was mine. I posted in javascript support so somebody here could help me. Now I'm back with no help.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,247
Reaction score
1,204
First Language
English
Primarily Uses
RMMV
hmm i wonder...
What are you talking about? You just wrote this in a thread for basic JavaScript questions. Any questions about moderator actions have nothing to do with that. And if you had a question about a plugin, that also wouldn't have anything to do with this thread.

I don't see any thread of yours that was moved anyplace, unless it was completely deleted which they don't normally do.
 

shukrin

Villager
Member
Joined
Sep 2, 2021
Messages
22
Reaction score
2
First Language
English
Primarily Uses
RMMZ
What are you talking about? You just wrote this in a thread for basic JavaScript questions. Any questions about moderator actions have nothing to do with that. And if you had a question about a plugin, that also wouldn't have anything to do with this thread.

I don't see any thread of yours that was moved anyplace, unless it was completely deleted which they don't normally do.
sorry but i dont know how to reach the mod and i thought posting here probably had a chance of them reading this

yes they do moved my thread, it was just a small request hoping somebody look at my edits on a script that has a bug, it was turned into a comment (called "merge'") and placed in the original post from the author, which are already gone quiet and probably abandoned :(
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,247
Reaction score
1,204
First Language
English
Primarily Uses
RMMV
sorry but i dont know how to reach the mod and i thought posting here probably had a chance of them reading this
If you click the word "Help" in the first row of words you see on the page, it will take you to the forum rules, which include what to do when you disagree with moderator action. Of all the things you might do, randomly posting your question in an existing thread makes the least sense :guffaw:
 

cubeking1

Villager
Member
Joined
Dec 19, 2013
Messages
15
Reaction score
1
First Language
english
Primarily Uses
i'm trying to make a skill , using skill core, only visible under two conditions
actor has state and specific weapon equipped
or
actor has state and specific switch is on

i bet it is something small but what am i doing wrong?

<Custom Show Eval>

if (user.isStateAffected(22) && $gameActors.actor(1).isEquipped($dataWeapons[2]))

|| (user.isStateAffected(22) && $gameSwitches.value(1) == true) {

visible = true;

} else {

visible = false;

}

</Custom Show Eval>
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,247
Reaction score
1,204
First Language
English
Primarily Uses
RMMV
i bet it is something small but what am i doing wrong?
Well...a couple of things, not all that small.
if (user.isStateAffected(22) && $gameActors.actor(1).isEquipped($dataWeapons[2]))
There are two things wrong here. First, you're referencing user and $gameActors.actor(1), which means you may well be checking someone else's weapon. You should use user again.

Secondly, the format of a conditional statement is if (condition) stuff
You're closing out the parentheses in the statement above, which means the only part of this that's actually getting evaluated is if state and weapon - because the if state and switch is in an entire separate set of parentheses, it doesn't mean anything.

So if you want to do if ((thing && thing) || (thing && thing)) they all need to be inside one set of parentheses, like that. However, the entire construct is unnecessary, as boolean AND has a higher precedence than OR in the order of operations, so you don't need those extra parentheses at all.

In this specific case, because you're starting with the same thing both times (having a specific state), you can make it even shorter by asking if (thing && (thing || thing))
visible = true;

} else {

visible = false;
It's not anything wrong, but a couple of tips to make your code a bit cleaner here.
1) A conditional (if/else) automatically applies to the next single statement. You only need braces if you have multiple code statements that you want included in that condition. So you can simply do:
Code:
if (condition)
    thing
else
    thing

2) Any time you find yourself making an if/else where the only thing you do is say one thing is true or false, you can always get rid of that and just set it in the original condition. You also don't need to check if things == true or false, you can just ask if thing or if !thing (which you did in most of it, except for the switch for some reason). So a more efficient version, with the correct syntax for your condition, is:
Code:
<Custom Show Eval>
visible = user.isStateAffected(22) && (user.isEquipped($dataWeapons[2]) || $gameSwitches.value(1));
</Custom Show Eval>

P.S. You should always use the code tags in your forum posts (the </> icon), so that it preserves your indents and brackets.
 
Last edited:

LadyBaskerville

Hell-poodle
Veteran
Joined
Sep 12, 2016
Messages
660
Reaction score
555
First Language
German
Primarily Uses
RMMV
Is it possible to get the events/number of events on a map that the player is not currently on?

$gameMap.events() returns the events on the map where the player is, but say e.g. I'm on map 3 and want to find the number of events on map 5. Is that possible with a script call?
 

raffle

Veteran
Veteran
Joined
Oct 25, 2020
Messages
70
Reaction score
14
First Language
English
Primarily Uses
RMMV
Hey everyone, in rpg maker mv, is there a script call for when an item is used?

I have a fishing pole as a normal non consumable item (so i cant make a variable to check for quantity changes) and whenever I use it from a hotbar my fishing minigame starts, I'm using region ids to determine the fishing nodes and I just want to make it so if the fishing pole is used in region 30, the minigame starts.

So something like
if : script : $gamePlayer.regionId()==30 && (the item "fishing pole" was used) = run common event

Thanks for reading :LZSsmile:
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,247
Reaction score
1,204
First Language
English
Primarily Uses
RMMV
Is it possible to get the events/number of events on a map that the player is not currently on?
I'll be interested to see if anyone else says differently, but from what I can see, no. It looks like the entirety of map data is loaded from disk when they're accessed, then purged when left. Even self-switches, which can be set externally, aren't actually kept inside the map events, but in an external list.
Hey everyone, in rpg maker mv, is there a script call for when an item is used?
if : script : $gamePlayer.regionId()==30 && (the item "fishing pole" was used) = run common event
You're approaching this slightly backwards - you would attach a common event to your fishing pole in the Effects list, so that gets called every time you use the pole.

You can actually do this without scripting: you'd use event commands to Control Variable twice and store the X and Y value of the player's current position, then use the Get Location Info on tab 3 to store the region ID into a third variable. Then you do a Conditional Branch checking the value of that variable.

If you want to use a script call to make that more efficient, then it's Conditional Branch -> Script -> $gamePlayer.regionId()==30

Either way, you'd use that conditional, then just call your fishing game event from that.
 

raffle

Veteran
Veteran
Joined
Oct 25, 2020
Messages
70
Reaction score
14
First Language
English
Primarily Uses
RMMV
Thank you so much once more, it's working perfectly now :D
 

ST0RMTiger

Veteran
Veteran
Joined
Sep 17, 2021
Messages
38
Reaction score
31
First Language
German
Primarily Uses
RMMZ
I'll be interested to see if anyone else says differently, but from what I can see, no. It looks like the entirety of map data is loaded from disk when they're accessed, then purged when left. Even self-switches, which can be set externally, aren't actually kept inside the map events, but in an external list.
You are quite correct as there is no variables to access this values. They are indeed generated dynamically on map load. But this is also the answer: It has to be possible, because the game itself does this on every map load.

So i pulled all related functions together and endet up with a (somehow) functioning way:

1.) Put this code in a plugin
JavaScript:
var _myRequestedMapData = {};
function loadMyMapData (mapId) {
    if (mapId > 0) {
        const filename = "Map%1.json".format(mapId.padZero(3));
        console.log(filename);
        loadDataFile("$dataMap", filename);
    } else {
        //this.makeEmptyMap();
    }
}

function loadDataFile (name, src) {
    const xhr = new XMLHttpRequest();
    const url = "data/" + src;
    xhr.open("GET", url);
    xhr.overrideMimeType("application/json");
    xhr.onload = () => onXhrLoad(xhr, name, src, url);
    xhr.onerror = () => onXhrError(name, src, url);
    xhr.send();
}

function onXhrError (name, src, url) {
    const error = { name: name, src: src, url: url };
    console.log(error);
}

function onXhrLoad (xhr, name, src, url) {
    if (xhr.status < 400) {
        _myRequestedMapData = JSON.parse(xhr.responseText);
    }
}

2.) Call this from as a script call ingame
JavaScript:
let mapId = 3;
loadMyMapData(mapId);

Then the reqired values are obtained as:
_myRequestedMapData to gain all Map data
_myRequestedMapData.events.length to gain the event count on that map

The only problem is the asynchronous callback function that handles the file load. So in most times that value is obtained directly, but it may also still be the old value of a former map data request (or undefined).
 

Chaos17

Dreamer
Veteran
Joined
Mar 13, 2012
Messages
1,318
Reaction score
492
First Language
French
Hi,

Where can I find the function to edit the location of faceset in a dialog box?
 

ST0RMTiger

Veteran
Veteran
Joined
Sep 17, 2021
Messages
38
Reaction score
31
First Language
German
Primarily Uses
RMMZ
@Chaos17

you may mean
JavaScript:
Game_Message.prototype.setFaceImage = function(faceName, faceIndex)
 

ST0RMTiger

Veteran
Veteran
Joined
Sep 17, 2021
Messages
38
Reaction score
31
First Language
German
Primarily Uses
RMMZ
No, I really meant to move it out and not to call it separately like in this picture featuring an MZ plugin.
Ah okay.

The Face Image is drawn here:
JavaScript:
Window_Message.prototype.drawMessageFace = function() {
    const faceName = $gameMessage.faceName();
    const faceIndex = $gameMessage.faceIndex();
    const rtl = $gameMessage.isRTL();
    const width = ImageManager.faceWidth;
    const height = this.innerHeight;
    const x = rtl ? this.innerWidth - width - 4 : 4;
    this.drawFace(faceName, faceIndex, x, 0, width, height);
};

You have to change this function to drawFace on other X/Y positions
this.drawFace(faceName, faceIndex, YOUR_X, YOUR_Y, width, height);

This plugin that you mentioned seems to make a new window to draw on beforehand.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,247
Reaction score
1,204
First Language
English
Primarily Uses
RMMV
You are quite correct as there is no variables to access this values....But this is also the answer: It has to be possible
Obviously it's possible, or the games couldn't be played :stickytongue:

But that is substantially more complicated than "a script call" that the OP was asking about.
 

Sethorion

Villager
Member
Joined
May 8, 2015
Messages
25
Reaction score
8
First Language
English
Primarily Uses
How can I get events/enemies that are at x/y tile relative to the main actor? (Example; I press 'a' to slash my sword left. I want to damage enemies on the tile directly left of me)
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,247
Reaction score
1,204
First Language
English
Primarily Uses
RMMV
How can I get events/enemies that are at x/y tile relative to the main actor? (Example; I press 'a' to slash my sword left. I want to damage enemies on the tile directly left of me)
So you can do that with a few lines of code, but before going through that - you do know there are existing plugins to give you an on-map battle system? If you look for ABS you'll find plenty of stuff already written, which may save you considerable time.
 

Latest Threads

Latest Profile Posts

Woot got a promotion and a pay rise ᕙ( • ‿ • )ᕗ now I'm set.
does anyone feel like explaining to me the difference between simulation and emulation? you have my full permission to be as pedantic as you want.
About the Deer, I had to cut some piece of video due the *swearing* Youtube copyrights issues...
A caveman pokes his head in...
I was listening to songs by Chuck E Cheese's voice actor (Jaret Reddick from Bowling for Soup) when the meds I was taking for my stomach virus apparently stopped working. I can't take my next dose until morning, but it's no use anyway. I'm officially sick again. Of course, I'll definitely take the next dose either way, but it's useless now.

Forum statistics

Threads
116,006
Messages
1,094,859
Members
151,311
Latest member
OpenWings
Top