objet is not a function.

Status
Not open for further replies.

XGuarden

Veteran
Veteran
Joined
May 10, 2016
Messages
446
Reaction score
17
First Language
French
Primarily Uses
When I run this code I get objet is not a function if the code go to the default switch.
Any idea why% thanks.

Code:
var tint=$dataMap.meta.tint;
switch(tint) {
case "night": $gameScreen.startTint([-102,-85,0,170], 1); break;
case "morning": $gameScreen.startTint([-34,-17,10,68], 1); break;
case "day": $gameScreen.startTint([0,0,0,0], 1); break;
case "evening": $gameScreen.startTint([17,-34,-68,17], 1); break;
case undefined: break;
default:
var t=tint.split(',').map(Number);
$gameScreen.startTint([t(0),t(1),t(2),t(3)], 1);
}
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,365
Reaction score
7,674
First Language
German
Primarily Uses
RMMV
no, you don't - you have a typo there somewhere (object or objet? that is a big difference).
Which is why we always ask for screenshots of the error messages, simply because without we have to guess if the typo was in retyping the error message here, or because the original error was a typo in the original code.
 

XGuarden

Veteran
Veteran
Joined
May 10, 2016
Messages
446
Reaction score
17
First Language
French
Primarily Uses
no, you don't - you have a typo there somewhere (object or objet? that is a big difference).
Which is why we always ask for screenshots of the error messages, simply because without we have to guess if the typo was in retyping the error message here, or because the original error was a typo in the original code.
object
 

Fornoreason1000

Black Sheep
Veteran
Joined
Mar 1, 2014
Messages
206
Reaction score
95
First Language
English
Primarily Uses
RMMV
okay so the problem of the codes here? its kinda hard to help with out any context of your problem. telling us the error code and what you are trying to achieve is invaluable when it comes to debugging code. A screen shot of the console (press F8) is also very helpful. but lets look at this default block in the switch statement in the code you posted above.

Code:
var t=tint.split(',').map(Number);
$gameScreen.startTint([t(0),t(1),t(2),t(3)], 1);
this code makes little sense without any context as I jsut said, but there's a couple of things fundamentally wrong here.
I'm going to focus on that first line before tackling the second.
now I'm going to assume that tint is a String Object and that you know that String.split() returns an Array of strings.
Array.map(callbackFunction) returns a new array with the function applied to each element. putting Number converts the strings into numbers. so now we have an Array of Numbers.

Now the second line you call $gameScreen.startTint which takes a four element array( a Tone has four elements , red blue green and gray). you've also seem to be trying to call the array as a function like this:
Code:
t(0)

This is undoubtedly the cause of your error. An array cannot be called like a function. I think what you were trying to do was get the elements of that array. when doing this you want to use square brackets [ ], not regular brackets ( ),
getting array elements is done like this.

Code:
var myArray = [255,255,255]
var secondElement = myArray[1] //gets second element of array
Hope it helps
 

XGuarden

Veteran
Veteran
Joined
May 10, 2016
Messages
446
Reaction score
17
First Language
French
Primarily Uses
You got it right, I made the mistake to put () instead of
[].
 
Status
Not open for further replies.

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,860
Messages
1,017,038
Members
137,568
Latest member
invidious
Top