ID:172393
 
Hiya! I've been making a pretty cool RPG, but when doing the magic system, i got whacked by an error even i cant fix.

This code doesn't seem to work... i've tried every variation to it too. nothing can fix this dying monster.

var/spell_use=input("Which spell do you want to use?") in list(P.spells)

Basiclly what happens (This is inside a proc, so go with it.) is when it gets to this line. the input screen never pops up. DM doesn't even give me an error. the thing just stops!

I'd really appreciate some help.
P.S. If you need more code to understand, pls tell me
Well, one possible problem is that that bit of code isn't inside a verb, and usr is not the player.

input("Which spell do you want to use?") is *really* input(usr, "Which spell do you want to use?")

Try making it
input(variableOfThePlayer, "Which spell do you want to use?")
In response to Jon88
Well, that sounds like it would work
*Goes and tries*
Nope... that didn't do it. BTW i made sure P was the usr, and usr was P, it just doesen't want to display the list...
However. when i turned input into an alert

var/spell_use=alert(P,"Which spell do you want to use?",,P.spells)

it reaveals to me the whole list in one box. the box doesn't do anything but close the window however when i click it (thats cause be if() statement afterwards.)
You already(or should already) have spells defined as a list. list(P.spells) is making a new list and putting the spells list in it. Just use P.spells.
In response to YMIHere
oh, yeah... i already tried that but it didn't work either.
[that is, if you were talking about this]
var/spell_use=input(P,"Which spell do you want to use?")in P.spells
In response to Redslash
I ran a test and it worked fine, maybe the problem lies elsewhere?

Test:
mob/var/spells=list("Fire","Blizzard","Thunder")
mob/verb/Cast()
CastSpell(usr)
mob/proc/CastSpell(mob/P)
var/spell_use=input(P,"Which spell do you want to use?") in P.spells
world<<"[P] has cast [spell_use]."
In response to YMIHere
Hey.... i found out why it wasn't working, but still ned some help on the reason.

my defining of spells var was
mob/var/spells
however, when i changed it to...
mob/var/spells=list()

it started working, anyone have any clues as to why this var worked when my old one didn't?
In response to Redslash
Your old one wasn't a list, it was just a regular variable.
In response to Redslash
Redslash wrote:
Hey.... i found out why it wasn't working, but still ned some help on the reason.

my defining of spells var was
mob/var/spells
however, when i changed it to...
mob/var/spells=list()

it started working, anyone have any clues as to why this var worked when my old one didn't?

Because you never initialized the old one. It was null, and didn't even know it was supposed to be a list type. However, this is the wrong way to initialize a list belonging to a mob.

The correct way to initialize this list is to do it in mob/New() or whenever you'll need it.
// better
mob
var/list/spells

proc/AddSpell(spell)
if(!spells) spells = new
spells += spell

Lummox JR
In response to Lummox JR
LummoxJR
When i try that, gives me a "missing left hand argument" to the if statement. am i susposed to put who ever is gaining the spells in there or what?
In response to Redslash
Redslash wrote:
LummoxJR
When i try that, gives me a "missing left hand argument" to the if statement. am i susposed to put who ever is gaining the spells in there or what?

My guess is you integrated the code in a way different from what I showed you. I'd have to see the line that's the problem.

Lummox JR
In response to Redslash
Are you sure that P.spells is not equal to null?
Also remember that if a list has only one value, you will no be prompted to choose it as it will be automatically chosen. This might explain why you were not asked to select a spell.