ID:175161
 
I'm working on a very simple turn-based system to start me off, but keep getting these errors with this...

mob
proc
Attack(M as mob in view())
var/list/Enemies()=new()
Enemies += M
Enemies -= usr
switch(input("Who to attack?")in list(Enemies,"Cancel"))
if(Enemies)
var/Damage=usr.Strength-src.Defense
src.HP-=Damage
usr << "You did [Damage] damage to [src]!"
Death()
usr.IsMyTurn=0
if("Cancel")
return
____________________________________________________
check.dm:67:error::invalid expression
check.dm:70:error:Enemies:expected a constant expression
____________________________________________________
I'm new to lists as well and I've had problems with them, so I'm not sure what I'm doing wrong.
Syier wrote:
I'm working on a very simple turn-based system to start me off, but keep getting these errors with this...

mob
proc
Attack(M as mob in view())
var/list/Enemies()=new()
Enemies += M
Enemies -= usr
These two Enemies references arent meant to be indented (Tabbed).

switch(input("Who to attack?")in list(Enemies,"Cancel"))
The in list part is a little messed here. What you want to do is add "Cancel" too the list, then make the input() in enemies.
By putting in list(blablabla) your creating a new list for the input, so what you were doing there is asking it to select from a list which contains another list and "Cancel".
if(Enemies)
var/Damage=usr.Strength-src.Defense
src.HP-=Damage
usr << "You did [Damage] damage to [src]!"
Death()
usr.IsMyTurn=0
if("Cancel")
return
Here you want to make it so that instead of switch(input()), if(Enemies) then if("Cancel"), you have var/i = input(), then if(i == "Cancel") then else with all the damage stuff in it.


I hope that cleared things up. Its a little hard to explain since I had to swap a few things and add/remove others.
Unless this proc is meant to be added to the verbs list and used as a verb, then it needs to be totally rewritten.

As a rule of thumb, if you don't know the difference between src and usr, never put usr in procs.

Lummox JR