ID:148281
 
I have a spell proc for a battle system im making, but with the current code here, it dont actually ask you what spell you want to cast, it just automatically casts the first one on the list. Can anyone help me?

Heres the code:
Spell()
if(usr.spells == 0)
usr << "You have no spells!"
Battle()
else
input("What spell do you wish to cast?","Spells",spelllist) in spelllist
if("Blaze")
Blaze()
if("Heal")
Heal()
if("Firebal")
Firebal()
if("Cancel")
Battle()

All the procs are defined, but they are rather big, and getting to Spell() isnt the problem. Can anyone spot the problem for me?
Metroid wrote:
I have a spell proc for a battle system im making, but with the current code here, it dont actually ask you what spell you want to cast, it just automatically casts the first one on the list. Can anyone help me?

Heres the code:
Spell()
if(usr.spells == 0)
usr << "<font color = blue>You have no spells!</font>"
Battle()
else
input("What spell do you wish to cast?","Spells",spelllist) in spelllist
if("Blaze")
Blaze()
if("Heal")
Heal()
if("Firebal")
Firebal()
if("Cancel")
Battle()

Actually it should be casting each of those spells in order, or at least calling their procs.

The reason is you're not using switch(). Outside of a switch(), if("string") is always interpreted as true; so Blaze() is always called, Heal() is always called, Firebal() is always called, and Cancel() is always called. (Incidentally you can add "as null|anything" before the "in spelllist" for your input() to show a cancel button. That's a little nicer, presentation-wise.)

In fact, you're not catching the return value from input(), so basically your proc is asking a question and not listening to the answer.

All the procs are defined, but they are rather big, and getting to Spell() isnt the problem. Can anyone spot the problem for me?

One more problem: Fireball has two L's.

Lummox JR
In response to Lummox JR
Now i get Main.dm:415:error: missing left-hand argument to in.
In response to Metroid
Metroid wrote:
Now i get Main.dm:415:error: missing left-hand argument to in.

You didn't actually keep the quotes around "as null|anything" when you put it in, did you? Or when you created a switch() did you put parentheses around the input() itself but not the "in spelllist" after it?

It'd help if you actually posted the changes you made.

Lummox JR
In response to Lummox JR
ok here
Spell()
if(usr.spells == 0)
usr << "<font color = blue>You have no spells!</font color = blue>"
Battle()
else
switch(input("What spell do you wish to cast?","Spells",spelllist)) in spelllist
if("Blaze")
Blaze()
if("Heal")
Heal()
if("Firebal")
Firebal()
if("Cancel")
Battle()
In response to Metroid
Metroid wrote:
switch(input("What spell do you wish to cast?","Spells",spelllist)) in spelllist

Yep. You forgot to put the closing parenthesis after "in spelllist", and instead you put it before.

You also need to indent the if() statements under it.

Lummox JR
In response to Lummox JR
Spell()
if(usr.spells == 0)
usr << "<font color = blue>You have no spells!</font color = blue>"
Battle()
else
switch(input("What spell do you wish to cast?","Spells",spelllist) in spelllist)
if("Blaze")
Blaze()
if("Heal")
Heal()
if("Firebal")
Firebal()
if("Cancel")
Battle()

is that what i need? cause i tried it and it doesnt do anything after i hit Spell in my battle
In response to Metroid
Metroid wrote:
Spell()
if(usr.spells == 0)
usr << "<font color = blue>You have no spells!</font>"
Battle()
else
switch(input("What spell do you wish to cast?","Spells",spelllist) in spelllist)
if("Blaze")
Blaze()
if("Heal")
Heal()
if("Firebal")
Firebal()
if("Cancel")
Battle()

is that what i need? cause i tried it and it doesnt do anything after i hit Spell in my battle

That does look right now. The only thing I can think of is that spelllist is empty or nearly empty so something's being chosen by default, and whatever it is the name isn't exactly what it's supposed to be. One way to tell will be to put something after the if("Cancel"):
else
world.log << "Error: Bad spell choice \"[spelllist[1]]\""
It could be as simple as naming something in the list "blaze" instead of "Blaze".

Lummox JR
In response to Lummox JR
Ive tried it, ive looked at everything, is there another way i can get it to show a list of spells so they can pick one?