JavaScript questions that don't deserve their own thread

Prescott

argggghhh
Veteran
Joined
Aug 28, 2014
Messages
505
Reaction score
410
First Language
English
Primarily Uses
RMMV
If you just want the date and month:

Code:
let date = new Date();

$gameVariables.setValue(1, date.getDate() + "/" + (date.getMonth() + 1));
Or the other way round if you want US date format.
Ah I was fiddling around with it and all I missed was that first line. Good to know, thanks for your help!
 

GoodSelf

Zhu Li! Do the thing!
Veteran
Joined
Jul 23, 2016
Messages
594
Reaction score
1,112
First Language
English
Primarily Uses
RMMV
Hello! I'm trying to obtain the Item ID of the last item used by the player, then call that in a conditional branch. Since all 40+ items utilize the same Common Event, it seems silly to create 40 separate ones. I feel like I'm missing something here...can someone help out?

I saw this thread with a good response from Gamefall Team, but I don't believe it shows how to obtain the ID. Anyway, thanks again!
 

Doktor_Q

I'm not a real doktor, but I am a real Q
Veteran
Joined
Aug 1, 2016
Messages
814
Reaction score
500
First Language
English
Primarily Uses
RMMV
Hello! I'm trying to obtain the Item ID of the last item used by the player, then call that in a conditional branch. Since all 40+ items utilize the same Common Event, it seems silly to create 40 separate ones. I feel like I'm missing something here...can someone help out?

I saw this thread with a good response from Gamefall Team, but I don't believe it shows how to obtain the ID. Anyway, thanks again!
I looked around a bit, and originally thought $gameParty.lastItem().itemId() would work, but that's the last item you selected, for cursor memory purposes, not the last item actually used, so if two different actors used different items, they'd both read as being the second one selected.

A better alternative seems to be storing the item ID in a variable from within the item execution itself- this is much easier if you're using something like Yanfly's Skill Core, which gives you access to lunatic mode tags that can run whatever javascript you want at specific points, but you could also stick it in a damage formula. The code for that would be:
JavaScript:
$gameVariables.setValue(VariableNumberGoesHere, item.id);
If you're using a damage formula already, just stick that code at the beginning, before the actual damage formula.

[EDIT] Fixed "set" to "setValue" in the code.
 
Last edited:

GoodSelf

Zhu Li! Do the thing!
Veteran
Joined
Jul 23, 2016
Messages
594
Reaction score
1,112
First Language
English
Primarily Uses
RMMV
@Doktor_Q So, I typed this in, and tried to get it to work, but it's just not happening. Would you be able to PM me? I would very much appreciate the help!

Edit:
@Doktor_Q Yeah, that fixed it! This is awesome, thanks so much!
 
Last edited:

Kupotepo

Fantasy realist
Veteran
Joined
Jul 5, 2017
Messages
1,482
Reaction score
1,364
First Language
Thai
Primarily Uses
RMMV
I am trying to make Steal & Snatch (YEP) http://www.yanfly.moe/wiki/Steal_&_Snatch_(YEP).
I want to create a customize stealing in which an actor gets the amount of Money from stealing is equal to the user. Level x user.Speed

<After Steal Effect>
gameParty.gainGold() += user.level * user.agi;
</After Steal Effect>
Is this correct? Thank you for helping me.
 

Doktor_Q

I'm not a real doktor, but I am a real Q
Veteran
Joined
Aug 1, 2016
Messages
814
Reaction score
500
First Language
English
Primarily Uses
RMMV
@GoodSelf Re-checked the code, I typed "set" when it should have been "setValue". Edited my previous post, try that instead.

@Kupotepo No, you have the syntax a bit wrong. A correct version would be $gameParty.gainGold(user.level * user.agi);

Further explanation if you're curious:
Anything with () after it is a function, that is, you're telling the code to perform an action, and the values inside the () are the parameters- in this case, $gameParty.gainGold is a function that adds money, and the parameter is how much money to add. Some functions, as part of doing their thing, will fetch information for you- such as a list of all living enemies, the tile position of a character on the map, etc. That's when you can do someValue = someFunction(), but you can't do someFunction() = someValue because someFunction() is a function, not a variable, and is not a place to store values. Sometimes, you might see a function like someObject.setSomeProperty(someValue)- in that case, the function's job is to store the parameter (someValue) in a different position, but it also can do other work at the same time, like making sure sprites get refreshed, keeping track of the previous value, etc.
 
Last edited:

GoodSelf

Zhu Li! Do the thing!
Veteran
Joined
Jul 23, 2016
Messages
594
Reaction score
1,112
First Language
English
Primarily Uses
RMMV
@Doktor_Q So, this works great, but I've seem to come across something else. The variable doesn't update when the scope is set to None. I don't want to have to select the character to use the item. I even downloaded the yanfly plugin and used the <Before Eval> tags and such, but it's still not working with a scope of None. Any ideas on this?
 

Doktor_Q

I'm not a real doktor, but I am a real Q
Veteran
Joined
Aug 1, 2016
Messages
814
Reaction score
500
First Language
English
Primarily Uses
RMMV
@Doktor_Q So, this works great, but I've seem to come across something else. The variable doesn't update when the scope is set to None. I don't want to have to select the character to use the item. I even downloaded the yanfly plugin and used the <Before Eval> tags and such, but it's still not working with a scope of None. Any ideas on this?
If the scope is None, then it won't run a damage formula, or any of the damage calculation related tags. However, <Custom Execution> in yanfly's skill core runs immediately after paying the skill's cost, so it should work even if you don't have a target.
 

Kupotepo

Fantasy realist
Veteran
Joined
Jul 5, 2017
Messages
1,482
Reaction score
1,364
First Language
Thai
Primarily Uses
RMMV
$gameParty.gainGold(user.level * user.agi);
Sorry. my memory is foggy. Is that for the note tag or script call?
I would like note tag in skill one.

How to customize the success rate like for example like success rate equal to 50 + User.Magic Attack?
user.hit = 50 + user.mat; Thank you for helping me.
 
Last edited:

GoodSelf

Zhu Li! Do the thing!
Veteran
Joined
Jul 23, 2016
Messages
594
Reaction score
1,112
First Language
English
Primarily Uses
RMMV
If the scope is None, then it won't run a damage formula, or any of the damage calculation related tags. However, <Custom Execution> in yanfly's skill core runs immediately after paying the skill's cost, so it should work even if you don't have a target.
Sadly, that didnt work for me, but it's okay! Thanks again for your help with the issue, I'm sure I'll make do.
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
70
Reaction score
22
First Language
English
Primarily Uses
RMMV
Edit: please delete.
 
Last edited:
Joined
Dec 15, 2014
Messages
81
Reaction score
41
First Language
English
Primarily Uses
RMMV
Is there any way to move these battlers closer to the bottom of the screen? I have yanfly core reposition battlers turned on. I didn't find that any settings in the other plugins changed it. I'm using larger resolution as well. Capture.PNG
It's not a big deal but it would look better with the larger enemies.
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
70
Reaction score
22
First Language
English
Primarily Uses
RMMV
Is there any way to move these battlers closer to the bottom of the screen? I have yanfly core reposition battlers turned on. I didn't find that any settings in the other plugins changed it. I'm using larger resolution as well. View attachment 151799
It's not a big deal but it would look better with the larger enemies.
Edit2:

Ok, I keep finding better methods doing this.
Hopefully this will be my last edit.

Download my plugin and put it somewhere after Yanfly plugins.
Now you have 2 options:

Option 1:
Go to "Enemies" setting and type into the Notes: <homeY:YOURVALUE> and/or <homeX:YOURVALUE> to set a fixed enemy position.

Option 2:
Go to plugin settings of this plugin and change the values of homeX and/or homeY in order to increase or decrease enemy position value.

So basically, if you want to move ALL your enemies down by lets say 200 pixel, you change the homeY value in the plugin settings to 200. You can of course, also set negative numbers for moving in opposite directions.

Hope this helps.
 

Attachments

Last edited:

Lady_JJ

Veteran
Veteran
Joined
May 6, 2019
Messages
46
Reaction score
22
First Language
English
Primarily Uses
RMMV
I have a need to place a list in a javascript variable as an array and then pick a random element of that array. I can do that with this event

1595377070176.png

The displayed variable looks like this

1595377159257.png

and I get the expected outcome

1595376883853.png

..... but, when I input that same text from a textfile, written the exact same way,

1595377386089.png

and replacing only the first line of code with

1595377552104.png

The output is different.

1595377670237.png

and that output isn't treated as an array.

1595377771889.png

I would be truly grateful if someone could tell me what steps I am missing. Thank you.

I forgot to mention that I am using Ozubon's plugin found here, though the problem is certainly my inept javascript and not in the plugin. The plugin works great.
 

Attachments

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
70
Reaction score
22
First Language
English
Primarily Uses
RMMV
I have a need to place a list in a javascript variable as an array and then pick a random element of that array. I can do that with this event

View attachment 152121

The displayed variable looks like this

View attachment 152122

and I get the expected outcome

View attachment 152119

..... but, when I input that same text from a textfile, written the exact same way,

View attachment 152123

and replacing only the first line of code with

View attachment 152124

The output is different.

View attachment 152127

and that output isn't treated as an array.

View attachment 152128

I would be truly grateful if someone could tell me what steps I am missing. Thank you.

I forgot to mention that I am using Ozubon's plugin found here, though the problem is certainly my inept javascript and not in the plugin. The plugin works great.
Have you tried saving your file as a ". json" and see if it recognizes that as an array?

Edit:
I looked at the code. It doesn't recognize your array, because the plugin reads the file's content as a string. So basically what you are getting when reading the file is "["cat", "dog", "mouse"]" instead of ["cat", "dog", "mouse"]. That's why ingame it appears as a regular array, because you don't see the quotation marks.

Your best solution is making your own .json file and telling the game where to access it.
You will need 2 things (it's really not hard, just bare with me):

First:
Your own costum plugin for your game that tells the game what files to look for.
JavaScript:
//=============================================================================
// Costum Files
//=============================================================================

var $dataList = null; // Create an object that will represent your costum file in MV

// Tell the game what your file is called (src: yourFile.json) and assign the object
// you created above to that file.
DataManager._databaseFiles.push({name: '$dataList', src: 'List.json'});
We will call this plugin "fileManager.js" (also attached for download).

Second:
You now can create your costum file. We will call it List.json in this case.
Simply insert your array ["dog", "cat", "bird", "mouse", "horse", "rabbit", "cow"] into a file, like you have done before and save the file as a .json. You can also for future purposes use arrays within your array so you don't need a new file for every list. You can also save objects in them of course.

The file List.json must be stored in the "data" folder, NOT JS or PLUGINS.

Edit2:
Maybe I should tell you how to access the file in MV lol.
Same as before basically, go to control variables and insert: $dataList

Hope this helps!
 

Attachments

Last edited:

Lady_JJ

Veteran
Veteran
Joined
May 6, 2019
Messages
46
Reaction score
22
First Language
English
Primarily Uses
RMMV
This is so perfect! Thank you very much. Works like a charm and now I can move on to adding details to the game.
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
70
Reaction score
22
First Language
English
Primarily Uses
RMMV
This is so perfect! Thank you very much. Works like a charm and now I can move on to adding details to the game.
I'm happy I could help :)
 
Joined
Dec 6, 2019
Messages
4
Reaction score
2
First Language
English
Primarily Uses
RMMV
Sorry if this an easy question!
How do you check the actor 1's sprite index via script call?
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
70
Reaction score
22
First Language
English
Primarily Uses
RMMV
Sorry if this an easy question!
How do you check the actor 1's sprite index via script call?
Are you talking about the character sprite of the first actor?
That would be in the array "SceneManager._scene._spriteset._characterSprites"
However, the array changes depending on how many other character sprites are on the map.
I'm not sure, but I think the first actor sprite is the last sprite in the array, the second actor in the second last one, etc.

So in the script you would go:

JavaScript:
var charSprites = SceneManager._scene._spriteset._characterSprites;
var actor1 = charSprites[charSprites.length - 1];
var actor2 = charSprites[charSprites.length - 2];
Edit:
That only works when you are in the map scene.
 
Last edited:

Users Who Are Viewing This Thread (Users: 0, Guests: 2)

Latest Threads

Latest Posts

Latest Profile Posts

Got inspired and started writing a simple tower defence battle system last night :o
Good news! I have located an amazing 3D website called SketchFab that has rotatable renderings of famous statues!
Picked up a physical copy of Megadimension Neptunia VII for the PS4 today. It's pretty good. I'm having a lot of fun with it.
The only upside of this remote semester was the plenty of funny photoshop material those facecams provided. Not that I would do that. Ever.

Forum statistics

Threads
100,516
Messages
976,711
Members
132,080
Latest member
nwr
Top