JavaScript questions that don't deserve their own thread

Kes

Regular
Regular
Joined
Aug 3, 2012
Messages
23,808
Reaction score
13,728
First Language
English
Primarily Uses
RMMZ
@Robro33 Thank you for the additional information. It all helps me to learn to avoid at least some of the more basic mistakes.
 

AmVa

Regular
Regular
Joined
Jul 6, 2022
Messages
105
Reaction score
30
First Language
English
Primarily Uses
RMMV
Is there a pixi.js equivalent for this script call?
$gameScreen.picture(n)._name = 'name';

In other words - if I want a sprite on the map scene to use a different image, but retain all its other properties (x, y, scale, anchor, etc..), how would you go about it?

What I'm currently doing is deleting the sprite via removeChild(), creating the new one, setting all the properties again, and adding the new sprite as a child. However I'm sure there's a more efficient way to do that I just haven't figured out yet.
 

DrBuni

Regular
Regular
Joined
Dec 27, 2020
Messages
234
Reaction score
142
First Language
.
Primarily Uses
RMMV
Is it possible to set animations to two frames only through code or otherwise?
 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
11,043
Reaction score
8,975
First Language
English
Primarily Uses
RMMV
Is it possible to set animations to two frames only through code or otherwise?
Animations are as many frames as you define them to be in the Animations tab.

Do you possibly mean sprite motions, as defined in Help -> Contents -> Documentation -> Side-view Character Standards?

If yes, you could either:
- Just paste one of the existing cels over one of the others, and you'll see only two frames
or
- You could look at Sprite_Actor.updateFrame(). Changing instances of 3 to 2 would probably do what you want, but I haven't carefully examined each line and its math. If you only want to affect battle and not, say, the characters walking on the map, you might need to copy contents from that into Sprite_Battler.updateFrame(), which is currently empty.
 

DrBuni

Regular
Regular
Joined
Dec 27, 2020
Messages
234
Reaction score
142
First Language
.
Primarily Uses
RMMV
Animations are as many frames as you define them to be in the Animations tab.

Do you possibly mean sprite motions, as defined in Help -> Contents -> Documentation -> Side-view Character Standards?

If yes, you could either:
- Just paste one of the existing cels over one of the others, and you'll see only two frames
or
- You could look at Sprite_Actor.updateFrame(). Changing instances of 3 to 2 would probably do what you want, but I haven't carefully examined each line and its math. If you only want to affect battle and not, say, the characters walking on the map, you might need to copy contents from that into Sprite_Battler.updateFrame(), which is currently empty.
First of all, thanks. I want 2 frame animations both in battles and otherwise (characters walking on the map).

Something like this: https://ibb.co/5cSzxy9

Reason being I am a decent artist, but lousy animator. It also fits perfectly with my game, and I like 2 frame animations. Plus, for combat abilities and such, I am drawing unique sprites and messing with camera and other juicy options, but that is probably too much information you are not interested on. Anyways, I will be looking into your suggestions in a bit, thanks again.
 

TESTOSTERONE

Nosey aren't ya?
Regular
Joined
Feb 11, 2017
Messages
470
Reaction score
2,414
First Language
English
Primarily Uses
RMMV
Code:
var min = 600; //10 minutes
var max = 900; //15 minutes
var frames = Math.random() * (max + 1 - min) + min;
this.wait(frames * 60);

Hi guys. I have the above as a common parallel event. The goal is for the game to wait for 10-15 minutes before respawning an event.

(Resolved) Could you help me out please with these two questions:
  1. Does this wait get reset every time the game is loaded? - Answer: no
  2. What about every time a player transfers maps? - Answer: yes
If yes to the above questions, would I have to increment a variable every second/minute instead to track how much time is left? - Answer: yes, however this will be paused during battles / menu screen. For true time interval, can use
Code:
$gameSystem.playtime()
.
 
Last edited:

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
11,043
Reaction score
8,975
First Language
English
Primarily Uses
RMMV
Does this wait get reset every time the game is loaded?
What about every time a player transfers maps?
So this.wait() is exactly what the Wait event command calls (I understand you're using a variable for the argument).

That does reset when changing maps. I did a simple test and it does not reset when the game is loaded.
 

TESTOSTERONE

Nosey aren't ya?
Regular
Joined
Feb 11, 2017
Messages
470
Reaction score
2,414
First Language
English
Primarily Uses
RMMV
That does reset when changing maps.
Thank you so much, Turan!
Aaaaaah, no wonder the event did not respawn while I test played going from one map to the next.;_;

Edit: @Arthann, would not have thought to use game time. That's genius! Thank you!!!
 
Last edited:

Arthran

Regular
Regular
Joined
Jun 25, 2021
Messages
1,091
Reaction score
1,571
First Language
English
Primarily Uses
RMMZ
Code:
var min = 600; //10 minutes
var max = 900; //15 minutes
var frames = Math.random() * (max + 1 - min) + min;
this.wait(frames * 60);

Hi guys. I have the above as a common parallel event. The goal is for the game to wait for 10-15 minutes before respawning an event.

Could you help me out please with these two questions:
  1. Does this wait get reset every time the game is loaded?
  2. What about every time a player transfers maps?
If yes to the above questions, would I have to increment a variable every second/minute instead to track how much time is left?
"Yes" to the second question. For the third question, that is an option, as long as you don't mind the timer pausing during battle and when the menu is open. However, with that method, the timer would lose a bit of accuracy every time the player changes maps, so I'd recommend using even smaller increments than seconds to minimize the accuracy loss.

Personally, I'd probably save $gameSystem.playtime() to a variable as soon as the event despawns, and then periodically subtract that value from the current value of $gameSystem.playtime() to determine whether or not enough time has passed in order for the respawn to occur.

That way, there is no accuracy loss, and the time spent in battles and in the menu will count. Depending on exactly what you're trying to do, it also could enable you to bypass the need for a parallel common event, since you'd only really need to check the time when it's relevant to do so (i.e. once you're actually on the map where the event is supposed to respawn).
 
Joined
Jul 17, 2017
Messages
4
Reaction score
1
First Language
English
Primarily Uses
RMMZ
I've been scouring for hours and can't find a way to actually remove the actor graphic from the cache to force an update. I'm trying to make a character customization plugin that saves to a character sheet, but I have to reboot the game to get the new graphic to load and that doesn't work for a character creator. I've tried clearing the cache, manually loading the bitmap, refreshing the actor, manually setting the image, using the image manager to load the url, everything I can think of. There's no reason the game shouldn't be able to reload one graphic after the initial load if I do something, given that it loaded it in the first place, but I don't know what that something is.
 

Kes

Regular
Regular
Joined
Aug 3, 2012
Messages
23,808
Reaction score
13,728
First Language
English
Primarily Uses
RMMZ
Starting from the simple - can you show us what your code looks like at this stage? It's not possible to trouble shoot something that no one has seen.
 
Joined
Jul 17, 2017
Messages
4
Reaction score
1
First Language
English
Primarily Uses
RMMZ
It's somewhat truncated because the statements reading pngs into an array or creating windows aren't relevant to the question and make the code a lot longer. This all works just how I want it except the refresh at the end where everything is commented out.

JavaScript:
 /* @command specific
 * @text Open Character Creator For Actor
 * @desc Opens the character creator for a specific actor.
 *       Enter the actor's ID.
 * @arg actor
 * @type number
 * @text Actor ID
 * @desc The ID of the actor you want to call.
 */

    PluginManager.registerCommand(pluginName, "specific", args => {
        characterBeingEdited = args.actor;
        filename = $gameActors.actor(characterBeingEdited).characterName();
        SceneManager.push(ShowCharacterCreator);
    });

//ShowCharacterCreator calls imageOverlay with an array of character parts pngs.

async function imageOverlay(characterArray) {
        //Reading array of images to layer
           let imageOne = await Jimp.read(characterArray[1]);
           let imageTwo = await Jimp.read(characterArray[2]);
           let imageThree = await Jimp.read(characterArray[3]);
           let imageFour = await Jimp.read(characterArray[4]);
           let imageFive = await Jimp.read(characterArray[5]);
        //Reading base image
           const imageZero = await Jimp.read(characterArray[0]);
        //Layering the images using Jimp node library
           imageOne = await imageOne
           imageZero.composite(imageOne, 0, 0, {
              mode: Jimp.BLEND_SOURCE_OVER
           })
           imageTwo = await imageTwo
           imageZero.composite(imageTwo, 0, 0, {
            mode: Jimp.BLEND_SOURCE_OVER
            })
            imageThree = await imageThree
            imageZero.composite(imageThree, 0, 0, {
            mode: Jimp.BLEND_SOURCE_OVER
             })
             imageFour = await imageFour
             imageZero.composite(imageFour, 0, 0, {
            mode: Jimp.BLEND_SOURCE_OVER
             })
             imageFive = await imageFive
             imageZero.composite(imageFive, 0, 0, {
            mode: Jimp.BLEND_SOURCE_OVER
         })
            //Write to actor's existing spritesheet in img/characters/
            url = "img/characters/" + filename + ".png";
            await imageZero.writeAsync(url);

           //Figure out how to refresh player character at runtime without closing out of the window
           //user = $gameActors.actor(characterBeingEdited);
           //user.setCharacterImage(filename, 0);
           //user.refresh();
           //$gameParty.leader().setCharacterImage(filename,0);
           //$gamePlayer.refresh(); 
           //ImageManager.clear();
           //PIXI.utils.TextureCache = {};
           //user.characterName = Bitmap.load(url);
           //????????
        }
 

Arthran

Regular
Regular
Joined
Jun 25, 2021
Messages
1,091
Reaction score
1,571
First Language
English
Primarily Uses
RMMZ
I've been scouring for hours and can't find a way to actually remove the actor graphic from the cache to force an update. I'm trying to make a character customization plugin that saves to a character sheet, but I have to reboot the game to get the new graphic to load and that doesn't work for a character creator. I've tried clearing the cache, manually loading the bitmap, refreshing the actor, manually setting the image, using the image manager to load the url, everything I can think of. There's no reason the game shouldn't be able to reload one graphic after the initial load if I do something, given that it loaded it in the first place, but I don't know what that something is.
Assuming you're using MZ, you can remove a specific character sheet from cache like this:
JavaScript:
const cache = ImageManager._cache;
const url =  "img/characters/" + Utils.encodeURI("Butt") + ".png";

if (cache[url]) {
    cache[url].destroy();
    delete cache[url];
}
Just replace Butt (on the second line) with the actual filename of the character sheet.
 
Joined
Jul 17, 2017
Messages
4
Reaction score
1
First Language
English
Primarily Uses
RMMZ
Assuming you're using MZ, you can remove a specific character sheet from cache like this:
JavaScript:
const cache = ImageManager._cache;
const url =  "img/characters/" + Utils.encodeURI("Butt") + ".png";

if (cache[url]) {
    cache[url].destroy();
    delete cache[url];
}
Just replace Butt (on the second line) with the actual filename of the character sheet.
Unfortunately, that still didn't update the actor's graphic. I don't really understand why it won't, because it seems like it should, but the actor's graphic remains the cached one even after the cache is cleared, even if I set it to something else and refresh it before clearing the cache.

EDIT: Solved the rest of the problem--I had a window that was loading the actor's sprite and I guess saved it for re-caching somehow because as soon as I commented out that particular line of code, it started updating just fine. Thanks for the help!
 
Last edited:

Kes

Regular
Regular
Joined
Aug 3, 2012
Messages
23,808
Reaction score
13,728
First Language
English
Primarily Uses
RMMZ
A typo has crept into a note tag I'm using to add splash damage to all enemies.

The note tag reads:
Code:
<JS Post-Damage>
for (let i=0; i<target.friendsUnit().aliveMembers().length; i++)
{
    if (target.friendsUnit().aliveMembers()[i]!=target)
    {
        target.friendsUnit().aliveMembers()[i].gainHp(0-Math.round(value/10));
        target.friendsUnit().aliveMembers()[i].startDamagePopup();
    }
}
</JS Post-Damage>

The console error message reads
1685478295798.png

The typo is in line 2 where it reads
i<target.friendsUnit()

That < is wrong, but I can't work out what it should be. Can anyone help me?
Thanks.
 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
11,043
Reaction score
8,975
First Language
English
Primarily Uses
RMMV
@Kes Are you sure you haven't added any other notetags or code or plugins? Changed a plugin parameter?

I don't see anything wrong in that code.
 

Kes

Regular
Regular
Joined
Aug 3, 2012
Messages
23,808
Reaction score
13,728
First Language
English
Primarily Uses
RMMZ
@ATT_Turan If I take that note tag out, I don't get the error message.
I haven't added or changed anything else (apart from a few tiles) between my last playtest and the one which gave this error message.

EDIT
Would this achieve the same thing?
Code:
<JS Post-Damage>
$gameTroop.aliveMembers().forEach(enemy => if (enemy!=target)
enemy.gainHp(0-Math.round(value/10)))
$gameTroop.aliveMembers().startDamagePopup();
</JS Post-Damage>
 
Last edited:

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
11,043
Reaction score
8,975
First Language
English
Primarily Uses
RMMV
@Kes No, that's not correct syntax. I'll put it this way - I can paste that code (plus a line above to define target and value) into the console of MZ and it executes perfectly.

Are there any other notetags on that skill?
 

Kes

Regular
Regular
Joined
Aug 3, 2012
Messages
23,808
Reaction score
13,728
First Language
English
Primarily Uses
RMMZ
@ATT_Turan Yes there is, it is to give a different sound effect if the attack lands a critical

Code:
<JS Post-Damage>
{
    if (target.result().critical)
        AudioManager.playSe({
        name: '101-Attack13',
        volume: 20,
        pitch: 100
        });
    else
        AudioManager.playSe({
        name: 'Slash',
        volume: 20,
        pitch: 100
        });
}
</JS Post-Damage>

This tag has been in for quite a while without problems.

EDIT
In case it makes a difference, this one is first in the note box, with the splash damage one second.
 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
11,043
Reaction score
8,975
First Language
English
Primarily Uses
RMMV
@Kes That's why - you can't duplicate notetags.

I would've expected it to simply not function, rather than to produce an error, but yeah. Unless a plugin is explicitly designed for it, and says you can, you can't put the same notetag onto a database entry more than once. You just need to put all of that code into one Post-Damage. (and I would take the first and last braces out of that, they're not doing anything)
 
  • Like
Reactions: Kes

Latest Threads

Latest Profile Posts

Resisting the urge to bust out watching spooky things all over. I still have days until it's Halloween month, gotta ration!
Made a free sample pack + leftovers. Free Sample Pack 1
I'm curious, how many hours in RPG Maker do you have? I'm clocked in at 2100 hours on MV and the vast majority of it is for one game. I wish I could track how much I used XP back in the day, I was on it a lot.
Why is it so early? Can I have twenty more minutes of sleep, please?
DK
Do you like this design?

GIF.gif

Forum statistics

Threads
134,810
Messages
1,250,849
Members
177,606
Latest member
Buffinto
Top