Math.max = NAN ?

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,439
First Language
French
Primarily Uses
RMMV
hI guys am trying to get the math.max of this script.


i need to create a lot of new variable dinamic for 


Objetposseder = [];


Objetposseder1, Objetposseder2, Objetposseder3, Objetposseder.....


And all variable have his own valur stored.


How i can found the variable (Objetposseder....) have the most higth valur. ???


Pid = 100; // picture ID for clic, 100 + max 36 Max 200
ItemtotalDB = 200;
Itemtotalposs = 0;
Objetposseder = [];
NBitempagemenu = 0;

for ( Listi=1; Listi < ItemtotalDB; Listi++) {
if ($gameParty.hasItem($dataItems[Listi]) == true){
Objetposseder[Listi] = Listi;//create based on DB
Itemtotalposs++;
console.log (Listi);
}
else {
Objetposseder[Listi] = 0;
}
}
console.log (Math.max(Objetposseder[]));




Have try this


Math.max(Objetposseder[]);
Math.max(Objetposseder[Listi]);






Tank you for your help guys
 
Last edited by a moderator:

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
564
Reaction score
275
First Language
German
Primarily Uses
Hi,


As far as I know, arrays in javascript start at index 0. You start initializing the array at index 1, so you probably have an entry in your array that is probably either nil or undefined that Math.max cannot handle.


Didn't work with arrays in javascript yet though.
 
Last edited by a moderator:

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,439
First Language
French
Primarily Uses
RMMV
Hi,


As far as I know, arrays in javascript start at index 0. You start initializing the array at index 1, so you probably have an entry in your array that is probably either nil or undefined that Math.max cannot handle.


Didn't work with arrays in javascript yet though.




more Example


i have this


Objetposseder[1] = 2;


Objetposseder[2] = 4;


Objetposseder[3] = 17;


Objetposseder[4] = 14;


I need to found what Objetposseder[?]


have the most higth valur
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
564
Reaction score
275
First Language
German
Primarily Uses
Uh, forgot one thing:
I'm not sure if  Math.max(Objetposseder[])  is valid javascript syntax.


In case it is not, you may try  Math.max.apply(this, Objetposseder)  instead.


As said in the previous post, you have to remove non-numeric values in order to get a useful result.


In this case it would probably be the easiest to start filling your array at index 0 instead of 1.
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
Last edited by a moderator:

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

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,868
Messages
1,017,066
Members
137,576
Latest member
SadaSoda
Top