Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

Type error help, object is not a function

Status
Not open for further replies.
I'm trying to get the highest value of 5 game variables, then turn on a switch depending on which one is the highest. Then store that value in a seperate game variable. i'm trying in different ways to make work, but I need help understanding the syntax. Here is my terrible code, please help. :)
JavaScript:
var i = [$gameVariables(141),
$gameVariables(142), $gameVariables(143),
$gameVariables(144), $gameVariables(145)];

Math.max(i);
//new script input from a common event:

if i = $gameVariables(141) {
$gameSwitches.setValue(133, true); }
if i = $gameVariables(142) {
$gameSwitches.setValue(134, true); }
if i = $gameVariables(143) {
$gameSwitches.setValue(135, true); }
if i = $gameVariables(144) {
$gameSwitches.setValue(136, true); }
if i = $gameVariables(145) {
$gameSwitches.setValue(137, true); }

//new script input from the same common event:
[code=JavaScript]var iE = Math.max($gameVariables(146),
$gameVariables(147), $gameVariables(148),
$gameVariables(149), $gameVariables(150),
$gameVariables(151), $gameVariables(152),
$gameVariables(153));
$gameVariables.setValue(154, iE);
[/code]
JavaScript:
if $gameVariables(154) = $gameVariables(146) {
$gameSwitches.setValue(141, true); }
if $gameVariables(154) = $gameVariables(147) {
$gameSwitches.setValue(142, true); }
if $gameVariables(154) = $gameVariables(148) {
$gameSwitches.setValue(143, true); }
if $gameVariables(154) = $gameVariables(149) {
$gameSwitches.setValue(144, true); }
if $gameVariables(154) = $gameVariables(150) {
$gameSwitches.setValue(145, true); }
if $gameVariables(154) = $gameVariables(151) {
$gameSwitches.setValue(146, true); }

if $gameVariables(154) = $gameVariables(152) {
$gameSwitches.setValue(147, true); }
if $gameVariables(154) = $gameVariables(153) {
$gameSwitches.setValue(148, true); }
[doublepost=1447647675,1447639514][/doublepost]I've figured it out:
JavaScript:
var i = 0;
i = Math.max($gameVariables.value(141),$gameVariables.value(142),$gameVariables.value(143),
$gameVariables.value(144),$gameVariables.value(145));
$gameVariables.setValue(155, i);

var i = $gameVariables.value(155);
if (i === $gameVariables.value(141))
{ $gameSwitches.setValue(133, true);}
if (i === $gameVariables.value(142))
{ $gameSwitches.setValue(134, true);}
if (i === $gameVariables.value(143))
{ $gameSwitches.setValue(135, true);}
if (i === $gameVariables.value(144))
{ $gameSwitches.setValue(136, true);}
if (i === $gameVariables.value(145))
{ $gameSwitches.setValue(137, true);}

var x = 0;
x = Math.max($gameVariables.value(146),$gameVariables.value(147),$gameVariables.value(148),
$gameVariables.value(149),$gameVariables.value(150),$gameVariables.value(151),$gameVariables.value(152),
$gameVariables.value(153));
$gameVariables.setValue(154, x);

if ($gameVariables.value(154) === $gameVariables.value(146))
{ $gameSwitches.setValue(141, true); }
if ($gameVariables.value(154) === $gameVariables.value(147))
{ $gameSwitches.setValue(142, true); }
if ($gameVariables.value(154) === $gameVariables.value(148))
{ $gameSwitches.setValue(143, true); }
if ($gameVariables.value(154) === $gameVariables.value(149))
{ $gameSwitches.setValue(144, true); }
if ($gameVariables.value(154) === $gameVariables.value(150))
{ $gameSwitches.setValue(145, true); }
if ($gameVariables.value(154) === $gameVariables.value(151))
{ $gameSwitches.setValue(146, true); }

if ($gameVariables.value(154) === $gameVariables.value(152))
{ $gameSwitches.setValue(147, true); }
if ($gameVariables.value(154) === $gameVariables.value(153))
{$gameSwitches.setValue(148, true); }
//end
 

eivl

Local Hero
Xy$
0.00
You would use the Math.max method on all your values, it returns the larges number.

JavaScript:
Math.max(num1,num2,num3,num4,num5);
 
This is for a Mix skill, I need it to find the greatest of 5 and the greatest of a different set of 8. To initiate 1/ 40 different mix skills. It works fine however when i use the skill a second time calling a forced action it freezes.
 

eivl

Local Hero
Xy$
0.00
Write console.log("Debug message"); on every line where you change something in your code to see where it freezes.
also disable any plugins that is not needed for this test.
 
Even JSLint says my code is good (except for undefined values that are defined in the rm engine). I will try disabling plugins... I do have many enabled... I can make this work fine without using forced battle abilities, but then I can't specify different damage types without it... or can I?
 

eivl

Local Hero
Xy$
0.00
your code looks fine, question is where in the code it breaks. you can also use a debugger and set breakpoints in your script, but using debuggers might be a hassle if you have no experience with it, in that case try it at your own sanity ;)
 

eivl

Local Hero
Xy$
0.00
if you want to debug in a browser, i recommend using the Chrome nightly build, called Canary.
https://www.google.com/chrome/browser/canary.html

I am hoping someone else can make a tutorial about JS debugging, but if it does not happen soon I will just step up and do it myself!
[doublepost=1447760018,1447759814][/doublepost]Firefox developer, safari/webkit, Xcode, or IE developer tool (not that anyone uses IE, but you can test it)

Android and ios have tools to debug from the mobile and look at the code on your desktop.
 

cav_dan

Towns Guard
Last edited:
Status
Not open for further replies.
Top