Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: bx83 on Mon 23/03/2020 22:17:18

Title: Can anyone tell me whats wrong with this code?
Post by: bx83 on Mon 23/03/2020 22:17:18
I have this code:

switch (player.Room) {
1:  candleobjnum=3; break;
2:  candleobjnum=7; break;
...
55: candleobjnum=1; break;
58: candleobjnum=-1; break;//no candlelight object
}


I tells the system what object number the "CandeLight" object was for each room. (next time I'm using a GUI :/)

When I run, I get the error: "improper argument '1' for Switch statement." or something of the like.

What is wrong with this? I thought 'switch (result of numer operation) { .... }' was the *only* argument you could put in there anyway?
Title: Re: Can anyone tell me whats wrong with this code?
Post by: ManicMatt on Mon 23/03/2020 23:55:14
I can't help you with that, but I do want to chime in that I needed an object to be animated from the global script, so instead I made the object a character.
Title: Re: Can anyone tell me whats wrong with this code?
Post by: Crimson Wizard on Tue 24/03/2020 00:09:15
You need to add "case" before each case value:
Code (ags) Select

switch (player.Room) {
case 1:  candleobjnum=3; break;
case 2:  candleobjnum=7; break;


There are examples in the manual: https://www.adventuregamestudio.co.uk/manual/ags43.htm#switchstatement
Title: Re: Can anyone tell me whats wrong with this code?
Post by: bx83 on Tue 24/03/2020 05:20:30
Oh dear, I've done a bad thing :/
Sorry guys.