JavaScript questions that don't deserve their own thread

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
70
Reaction score
22
First Language
English
Primarily Uses
RMMV
You can also use the scale.x and scale.y(or scaleX / scaleY?) Can't remember now, but you can use it to change the scale:
newSprite.scale.x = 2
newSprite.scale.y = 2
The default is 1.
I assume newSprite.scale.x = 1 is 100% size and then 2 would be 200% and so on? And that I need to do before adding the Sprite as a Child or could it also be done after?
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,418
Reaction score
671
First Language
Portuguese - Br
Primarily Uses
RMMV
I assume newSprite.scale.x = 1 is 100% size and then 2 would be 200% and so on? And that I need to do before adding the Sprite as a Child or could it also be done after?
Hi!
Yes, 1 means 100%, so 0.70 should mean 70%.
I think you can do it after or before add the child :)
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
70
Reaction score
22
First Language
English
Primarily Uses
RMMV
Hi!
Yes, 1 means 100%, so 0.70 should mean 70%.
I think you can do it after or before add the child :)
This opens up so many possibilities. Thank you very much :)
 

CHKNRAVE

I don't end projects, I start them.
Veteran
Joined
May 11, 2020
Messages
65
Reaction score
45
First Language
French
Primarily Uses
RMMV
Hello, I'm trying to set up a skill's targeting that's more advanced than anything I've done before. Here's how it should work:
If the enemy getting hovered over is isn't affected by a certain state:
The skill will affect that enemy only.
Otherwise,
The skill will affect every enemy in the row of the one getting hovered over.
I've got the different effects covered in the damage formula.

The relevant plugins for the situation are installed and set up: Target Core, Selection Control, and Row Formation. All 3 by Yanfly.
The issue is that I have no idea how to make it happen, I know how to define eligible targets but not some sort of AoE depending on the state of an enemy that's getting hovered over. Can somebody help me with that?
 
Last edited:

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,373
Reaction score
1,548
First Language
English
Primarily Uses
RMMV
Hello, I'm trying to set up a skill's targeting that's more advanced than anything I've done before. Here's how it should work:
If the enemy getting hovered over is affected by a certain state:
The skill will affect that enemy only.
Otherwise,
The skill will affect every enemy in the row of the one getting hovered over.
I've got the different effects covered in the damage formula.

The relevant plugins for the situation are installed and set up: Target Core, Selection Control, and Row Formation. All 3 by Yanfly.
The issue is that I have no idea how to make it happen, I know how to define eligible targets but not some sort of AoE depending on the state of an enemy that's getting hovered over. Can somebody help me with that?
I don't have Row Formation so I can't see the exact syntax for targeting an enemy row, but basically what you need to do is a Custom Target Eval:

Code:
<Custom Target Eval>
  if (!target.isStateAffected(id of state you're checking for)) {
    // target entire row
  }
</Custom Target Eval>
 

CHKNRAVE

I don't end projects, I start them.
Veteran
Joined
May 11, 2020
Messages
65
Reaction score
45
First Language
French
Primarily Uses
RMMV
I think I'm onto something, however my formula needs some extra work so the effect if the target has the state is applied to the entire row.

Here's what worked:
Code:
<Custom Target Eval>
if (target.isStateAffected(16)) {
  for (var i = 0; i < foes.aliveMembers().length; ++i) {
    var member = foes.aliveMembers()[i];
    if (member.row === target.row) targets.push(member);
  }
} else {
  targets.push(target);
}
</Custom Target Eval>
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,373
Reaction score
1,548
First Language
English
Primarily Uses
RMMV
You forgot the ! !target.isStateAffected(16)

You said you only wanted it to target the entire row if they *didn't* have that state, right?
 

CHKNRAVE

I don't end projects, I start them.
Veteran
Joined
May 11, 2020
Messages
65
Reaction score
45
First Language
French
Primarily Uses
RMMV
My bad, what I really wanted was to target the whole row if the enemy getting hovered over does have the state.
 

CG-Tespy

Villager
Member
Joined
Jan 5, 2019
Messages
20
Reaction score
9
First Language
Spanish
Primarily Uses
RMMV
How do I write to a file in a browser-friendly way? I know how to use XMLHTTPRequest to read a file, but all the solutions I found for writing require either...

- Using a server-side language like PHP
- Having some input element in the html file

Is there some way I can just use JS for this, without messing with the DOM or trying to find some hack that uses another language?
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,395
Reaction score
3,239
First Language
Java's Crypt
Primarily Uses
RMMV
How do I write to a file in a browser-friendly way? I know how to use XMLHTTPRequest to read a file, but all the solutions I found for writing require either...

- Using a server-side language like PHP
- Having some input element in the html file

Is there some way I can just use JS for this, without messing with the DOM or trying to find some hack that uses another language?
You can't write actual files when playing in the browser, you can only store data in the browser itself. And using a server language like php would write the files on the server, not on the player's pc.
 

CG-Tespy

Villager
Member
Joined
Jan 5, 2019
Messages
20
Reaction score
9
First Language
Spanish
Primarily Uses
RMMV
To my understanding, XMLHttpRequests are requests for servers to do things. Since I managed to use them to read files on disk, I assume that MV has the game's directory treated as server storage. Or is there something else that explains the following code working?

JavaScript:
let req = new XMLHttpRequest();
req.open("GET", path, false); // path is relative to the game's index.html file
req.send();
return req.responseText; // the file's contents
If I misunderstood, then would that mean that it's impossible to write to files on disk without breaking browser compatibility?
 

meowengine

Villager
Member
Joined
Jun 13, 2020
Messages
10
Reaction score
12
First Language
English
Primarily Uses
N/A
Hi I'm trying to figure out what this method of the "Window_Selectable" class is trying to return.
What exactly does "topIndex" mean and how can it be useful?
JavaScript:
Window_Selectable.prototype.topIndex = function () {
  return this.topRow() * this.maxCols();
};
So "maxCols()" returns the maximum number of columns of course, but I don't really understand what "topRow()" means.

JavaScript:
Window_Selectable.prototype.topRow = function () {
  return Math.floor(this._scrollY / this.itemHeight());
};
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,395
Reaction score
3,239
First Language
Java's Crypt
Primarily Uses
RMMV
To my understanding, XMLHttpRequests are requests for servers to do things. Since I managed to use them to read files on disk, I assume that MV has the game's directory treated as server storage. Or is there something else that explains the following code working?

JavaScript:
let req = new XMLHttpRequest();
req.open("GET", path, false); // path is relative to the game's index.html file
req.send();
return req.responseText; // the file's contents
XMLHttpRequests can read files because the browser can read files using the file:// protocol, but there's no way for browsers to write files on the user's disk.

If I misunderstood, then would that mean that it's impossible to write to files on disk without breaking browser compatibility?
That's correct, but you can still save data to the user's browser (the game saves, for example). You just can't save files.

Hi I'm trying to figure out what this method of the "Window_Selectable" class is trying to return.
What exactly does "topIndex" mean and how can it be useful?
JavaScript:
Window_Selectable.prototype.topIndex = function () {
  return this.topRow() * this.maxCols();
};
So "maxCols()" returns the maximum number of columns of course, but I don't really understand what "topRow()" means.

JavaScript:
Window_Selectable.prototype.topRow = function () {
  return Math.floor(this._scrollY / this.itemHeight());
};
topRow returns the first visible row on the window. When you scroll down a selectable window the topRow index will increase as more rows are hidden by the scroll.
 

Prescott

argggghhh
Veteran
Joined
Aug 28, 2014
Messages
505
Reaction score
410
First Language
English
Primarily Uses
RMMV
I'm trying to read the system clock's date for events that happen in my game that are restricted to certain dates in the real world. Is there a way to check what the current date is and if it matches the date I want it to be, to cause a switch to activate?
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,373
Reaction score
1,548
First Language
English
Primarily Uses
RMMV
1594207588547.png

Code:
$gameVariables.setValue(1, new Date().toLocaleDateString());
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,373
Reaction score
1,548
First Language
English
Primarily Uses
RMMV
Yeah, you can format the date basically any way you want. It's stored as "7/8/2020" in the variable; when you store a string in a variable and display it in a show text command it'll show exactly as it's stored. But the Date object has many functions for getting the individual parts of it.
 

CG-Tespy

Villager
Member
Joined
Jan 5, 2019
Messages
20
Reaction score
9
First Language
Spanish
Primarily Uses
RMMV
That's correct, but you can still save data to the user's browser (the game saves, for example). You just can't save files.
Ah, alright. Thanks for the answer :) Good thing MV supports the HTML Web Storage API, which is what you use to save to the browser. I'll leave a link here, in case someone else has the same problem I did.
 

Prescott

argggghhh
Veteran
Joined
Aug 28, 2014
Messages
505
Reaction score
410
First Language
English
Primarily Uses
RMMV
Yeah, you can format the date basically any way you want. It's stored as "7/8/2020" in the variable; when you store a string in a variable and display it in a show text command it'll show exactly as it's stored. But the Date object has many functions for getting the individual parts of it.
So, exactly how would I leave off the year? Or can you lead me to a resource that can give me some more info? Alternatively, is there a way to cut off the last 4 digits of a variable? Because that would also work, although I can't find anything like that. I tried dividing it by 10,000 to change the decimal point but it seems like trying to do anything to the variable will just set it back to 0 since it has "/" in it.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,373
Reaction score
1,548
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.
 

Users Who Are Viewing This Thread (Users: 1, Guests: 6)

Latest Threads

Latest Profile Posts

I haven't been able to solidify a cohesive plot so dropped out of a game jam but, on a fun note, I pre-ordered MZ today! :LZSwink:
So I just spent the weekend...playing my own game. The one I released last year. Yep you heard that right.
Goal for MZ? None... I'm still curious how to finish my VXA project and how it looks like when it actually finished. Which will take at least another two years. Coming late again to the party.
Finding it amusing that people are posting support questions in new threads for an engine that isn't even released yet. Touch and Archeia are the only ones authorised to say anything, and there's only one active thread where they'll be answering questions.
I think my goal for MZ ... is to actually release a game and not have twenty technical demos and debugging projects. Let's see if I can manage that. ;o

Forum statistics

Threads
100,654
Messages
978,112
Members
132,265
Latest member
annajones
Top