ID:1582177
 
(See the best response by Ssj4justdale.)
Code:
mob
proc
medals(medal)
switch(medal)
if("Login")//you can customize this so you can check for certain types of medals, such as "Combat", "Level", "Item Found"
var/has_medal = world.GetMedal("New Player",src)
if(has_medal) return//if they already have the medal, you don't want them to get it again
else
world.SetMedal("New Player Medal",src)//give them the medal
world<<"<font size=5><Font face=times new roman><font color=Yellow>:Congratulations! [usr] have acheived the 'New Player' Medal!:"
//customizable alert string ^
if("Logout")//just displaying how you can diversify it again
var/has_medal = world.GetMedal("Logout Medal",src)
if(has_medal) return
else
world.SetMedal("Logout Medal",src)
world<<"<font size=5><Font face=times new roman><font color=Yellow>:Congratulations! [usr] have acheived the 'Logout Medal' medal!"
if(level>5000)//you can customize this so you can check for certain types of medals, such as "Combat", "Level", "Item Found"
var/has_medal = world.GetMedal("Half Way",src)
if(has_medal) return//if they already have the medal, you don't want them to get it again
else
world.SetMedal("Half Way Medal",src)//give them the medal
world<<"<font size=5><Font face=times new roman><font color=Yellow>:Congratulations! [usr] have acheived the 'Half Way' Medal!:"
//customizable alert string ^


Problem description:
Programming\Medals.dm:18:error: : expected a constant expression

Could you identify which one is line 18?
Best response
Under the switch() you have if(level>500).

If you are going to do that, you need to do so like this:

mob
proc
medals(medal)
switch(medal)
if("Login")//you can customize this so you can check for certain types of medals, such as "Combat", "Level", "Item Found"
var/has_medal = world.GetMedal("New Player",src)
if(has_medal) return//if they already have the medal, you don't want them to get it again
else
world.SetMedal("New Player Medal",src)//give them the medal
world<<"<font size=5><Font face=times new roman><font color=Yellow>:Congratulations! [usr] have acheived the 'New Player' Medal!:"
//customizable alert string ^
if("Logout")//just displaying how you can diversify it again
var/has_medal = world.GetMedal("Logout Medal",src)
if(has_medal) return
else
world.SetMedal("Logout Medal",src)
world<<"<font size=5><Font face=times new roman><font color=Yellow>:Congratulations! [usr] have acheived the 'Logout Medal' medal!"
if(level>5000)//you can customize this so you can check for certain types of medals, such as "Combat", "Level", "Item Found"
var/has_medal = world.GetMedal("Half Way",src)
if(has_medal) return//if they already have the medal, you don't want them to get it again
else
world.SetMedal("Half Way Medal",src)//give them the medal
world<<"<font size=5><Font face=times new roman><font color=Yellow>:Congratulations! [usr] have acheived the 'Half Way' Medal!:"
//customizable alert string ^



you can not do expressions like
switch(medal)
if(level<500) //NOT ALLOWED!
if(500) //allowed.
if("500") //allowed.


SO no expressions under switch() okay?
In response to LordAndrew
LordAndrew wrote:
Could you identify which one is line 18?

It's his
if(level>5000) //line under a switch() statement.
Ssj4justdale is correct, but I think WHY it's not allowed needs to be elaborated as this is more a comprehension issue than anything.

switch() checks the following if() statements for the value of its argument. This means only numbers, strings, Boolean values, sets, and ranges (using "to") may be accepted, as switch() is not capable of expressions. level>5000 would require additional information that switch() does not have access to. Therefore you would have to perform that check outside of the switch(), as Ssj4justdale showed.
^ Thankyou. I'm already running on 24+ hours of no sleep and I couldn't find the words to state what you just did.
Not necessarily true:

These are all valid:

switch(x)
if(1)
if(2 to 5)
if(7)
if(6,8,10)
if(9)


Switch can only check if the value IS, IS IN RANGE, or IS IN SET.
In response to Ter13
Didn't know you could do ranges and sets. Guess I should have double checked my information with the reference. Thanks for pointing that out, though.
We all have gaps in our knowledge. Which is why we all are supposed to correct one another on this forum. A number of users around here correct me quite often as well. ;P
You earned my vote Ter, because I love what you said ^