UGX-Mods

Call of Duty 5: World at War => Help Desk => Scripting => Topic started by: Gabrielle on August 22, 2015, 10:09:25 am

Title: Cannot cast undefined to bool
Post by: Gabrielle on August 22, 2015, 10:09:25 am
Hey,

I was trying to make a script for my camo change. So I added a model to the map, clip around it, trigger with targetname 'switchcamo'. All good you should say.

I then made a script. New .gsc file with the following content:

Code Snippet
Plaintext
// Camo changer

init_camo_changer_variables()
{
level.camos = [];
level.camos[0] = "115";
level.camos[1] = "afterlife";
level.currentCamo = 0;
}

init_camo_changer_trigger()
{
nextCamoNr = level.currentCamo + 1;

if (nextCamoNr >= level.camos.size)
{
nextCamoNr = 0;
}

camo_changer_trigger = getent("switchcamo", "targetname");
camo_changer_trigger sethintstring("Press &&1 to change camo to " + level.camos[nextCamoNr]);

camo_changer_trigger waittill("trigger", player);

player giveWeapon("zombie_colt", "upgraded");
}

I rebuild my MOD and things started to become really messy. I got some weird ass number error which I can't remember, so I decided to remove everything from my map, remove the .gsc file from my MOD folder and comment out the function callings in _zombiemode.gsc. However, still, everytime I go to the map it gives me errors like cannot cast undefined to bool. If I click it away, after a split second it just comes back.

By the way, I don't know what the problem is with my script. I'm not the best scripter, I'm still learning, but is there anything I'm doing wrong?

Thanks in advance and have a nice day :)
Title: Re: Cannot cast undefined to bool
Post by: steviewonder87 on August 22, 2015, 11:12:14 am
Turn off developer 1?
Title: Re: Cannot cast undefined to bool
Post by: Gabrielle on August 22, 2015, 11:28:07 am
Turn off developer 1?

I'm dumb lol. Anyways nice avatar! But can you say whether something's wrong with my script or not?
Title: Re: Cannot cast undefined to bool
Post by: daedra descent on August 22, 2015, 11:35:52 am
You have developer set which gives debug information. If i where you i'd fix it but if your lazy and/or don't care if your map is broken you can do "developer 0" in the console.

As far as the script goes, your if condition isn't right. '>=' would be true if nextCamoNr is over or equal to the array size, so the "afterlife" camo would never get selected.

So change:

Code Snippet
Plaintext
	if (nextCamoNr >= level.camos.size)
{
nextCamoNr = 0;
}

to:

Code Snippet
Plaintext
	if (nextCamoNr > level.camos.size)
{
nextCamoNr = 0;
}

also you don't have the code in a while loop, so it'll only run once.
Title: Re: Cannot cast undefined to bool
Post by: Gabrielle on August 22, 2015, 11:39:36 am
You have developer set which gives debug information. If i where you i'd fix it but if your lazy and/or don't care if your map is broken you can do "developer 0" in the console.

As far as the script goes, your if condition isn't right. '>=' would be true if nextCamoNr is over or equal to the array size, so the "afterlife" camo would never get selected.

So change:

Code Snippet
Plaintext
	if (nextCamoNr >= level.camos.size)
{
nextCamoNr = 0;
}

to:

Code Snippet
Plaintext
	if (nextCamoNr > level.camos.size)
{
nextCamoNr = 0;
}

also you don't have the code in a while loop, so it'll only run once.

I wouldn't care about fixing but IDK what the problem is as I've removed everything I made today and it still gives me the errors while yesterday it worked. And I don't think the errors can be caused by the skybox.

Anyways, you're right I totally forgot, thanks for pointing it out.
Title: Re: Cannot cast undefined to bool
Post by: daedra descent on August 22, 2015, 11:42:01 am
I wouldn't care about fixing but IDK what the problem is as I've removed everything I made today and it still gives me the errors while yesterday it worked. And I don't think the errors can be caused by the skybox.

Anyways, you're right I totally forgot, thanks for pointing it out.

Doesn't the console give any more information?
Title: Re: Cannot cast undefined to bool
Post by: DidUknowiPwn on August 22, 2015, 03:28:31 pm
That giveWeapon is also bad.
2nd param follows weapon file gunmodel1 etc so 2nd param is an int
Title: Re: Cannot cast undefined to bool
Post by: Gabrielle on August 22, 2015, 04:17:35 pm
Doesn't the console give any more information?

When I use my script, I get the following error when starting up my map:

Code Snippet
Plaintext
script runtime error
(see console for details)
pair 'undefined' and 'NUMBER' has unmatching
types 'undefined' and 'float'

My console gives a shitload of errors:

(https://www.ugx-mods.com/forum/proxy.php?request=http%3A%2F%2Fi.imgur.com%2Ftihireq.png&hash=6cb10f1191011f00c1a59015dc8ead7f753a7a37)

Just some of them.

That giveWeapon is also bad.
2nd param follows weapon file gunmodel1 etc so 2nd param is an int

Didn't know. I was searching for like 50 minutes for the function declaration but couldn't find it anywhere. I just want to change the gun camo (which is ofc. another model). Don't want it to refill ammo though.
Title: Re: Cannot cast undefined to bool
Post by: BluntStuffy on August 22, 2015, 04:52:31 pm
Quote
When I use my script, I get the following error when starting up my map:

Code Snippet
Plaintext
script runtime error
(see console for details)
pair 'undefined' and 'NUMBER' has unmatching
types 'undefined' and 'float'

My console gives a shitload of errors:

Just some of them.

All those error's are basicly because of 'sloppy' scripting, variable's arent defined propperly and the result is it's checking against an undefined variable ( and that will Always come out true i believe ).

Now you say the error is about a variable called NUMBER ( i dont see that in your code anywhere ) , so it's prob related to some other script, or you have changed your code allready. Fixing those kind of errors is useally pretty easy, since it'll give you the script + line number and the variable's involved. 


Quote
Didn't know. I was searching for like 50 minutes for the function declaration but couldn't find it anywhere. I just want to change the gun camo (which is ofc. another model). Don't want it to refill ammo though.

For changing the cammo do like pwn said and use the number of the model you used in the weaponfile, so for example:

Code Snippet
Plaintext
player giveWeapon("zombie_colt", 2);
Then it will use the gunmodel2 and worldmodel2 from the weaponfile, if that refils your ammo you'd prob have to correct that yourself by getting clip and ammo count before swapping weapons, and then set those numbers on the 'new' gun. Use:

Code Snippet
Plaintext
player getweaponammostock( weapon )
player getweaponammoclip( weapon )

player setweaponammostock( weapon, amount )
player setweaponammoclip( weapon, amount )
Title: Re: Cannot cast undefined to bool
Post by: Gabrielle on August 22, 2015, 05:21:17 pm
All those error's are basicly because of 'sloppy' scripting, variable's arent defined propperly and the result is it's checking against an undefined variable ( and that will Always come out true i believe ).

Now you say the error is about a variable called NUMBER ( i dont see that in your code anywhere ) , so it's prob related to some other script, or you have changed your code allready. Fixing those kind of errors is useally pretty easy, since it'll give you the script + line number and the variable's involved. 


For changing the cammo do like pwn said and use the number of the model you used in the weaponfile, so for example:

Code Snippet
Plaintext
player giveWeapon("zombie_colt", 2);
Then it will use the gunmodel2 and worldmodel2 from the weaponfile, if that refils your ammo you'd prob have to correct that yourself by getting clip and ammo count before swapping weapons, and then set those numbers on the 'new' gun. Use:

Code Snippet
Plaintext
player getweaponammostock( weapon )
player getweaponammoclip( weapon )

player setweaponammostock( weapon, amount )
player setweaponammoclip( weapon, amount )

I only called the 2 functions in _zombiemode.gsc the rest i haven't touched. And thanks for your help.