ID:141213
 
Code:
mob
verb
Character_Sheet()
char_name
var/user_name = input("What would you like your name to be?","Name")as text
if(!user_name)
goto char_name
if(lentext(user_name) > 20)
src <<"Name too long."
goto char_name
for(var/N in un_wanted_names && html)
if(findtext(user_name,N))
alert("That name is not allowed.","Name")
goto char_name
else
src.name = html_encode(user_name)
switch(input("What class are you?", "Class") in list ("Uchiha","Hyuuga","Inuzuka","Aburame","Akimichi","Uzumaki"))
if("Uchiha")
src.Class = "Uchiha"
if("Hyuuga")
src.Class = "Hyuuga"
if("Inuzuka")
src.Class = "Inuzuka"
if("Aburame")
src.Class = "Aburame"
if("Akimichi")
src.Class = "Akimichi"
if("Uzumaki")
src.Class = "Uzumaki"
switch(input("What style fighter are you?","Style") in list ("Conservative(+5 HP)","Jutsu Specialist(+10 Chakra)","Defensive(Vitality + 5)","Taijutsu Master(+5 Str)"))
if("Conservative(+5 HP)")
src.Style ="Conservative"
src.HP +=5
src.Chakra = 0
src.Vitality = 0
src.Str = 0
if("Jutsu Specialist(+10 Chakra)")
src.Style = "Jutsu Specialist"
src.Chakra += 10
src.Vitality = 0
src.Str = 0
if("Defensive(Vitality + 5)")
src.Vitality += 5
src.Str = 0
if("Taijutsu Master(+5 Str)")
src.Str +=5
src.Vitality = 0
switch(input("How old are you?", "Age") in list ("16","17","18","19","20"))
if("16")
src.Age = 16
if("17")
src.Age = 17
if("18")
src.Age = 18
if("19")
src.Age = 19
if("20")
src.Age = 20
switch(input("How would you like to distribute your stat points? You have 12 remaining!","Stats") in list ("Vitality, Strength, Chakra, HP"))
if("Vitality")
src.Vitality +=1
if("Strength")
src.Str +=1
if("Chakra")
src.Chakra +=5
if("HP")
src.HP +=5
switch(input("How would you like to distribute your stat points? You have 11 remaining!","Stats") in list ("Vitality, Strength, Chakra, HP"))
if("Vitality")
src.Vitality +=1
if("Strength")
src.Str +=1
if("Chakra")
src.Chakra +=5
if("HP")
src.HP +=5
switch(input("How would you like to distribute your stat points? You have 10 remaining!","Stats") in list ("Vitality, Strength, Chakra, HP"))
if("Vitality")
src.Vitality +=1
if("Strength")
src.Str +=1
if("Chakra")
src.Chakra +=5
if("HP")
src.HP +=5
switch(input("How would you like to distribute your stat points? You have 9 remaining!","Stats") in list ("Vitality, Strength, Chakra, HP"))
if("Vitality")
src.Vitality +=1
if("Strength")
src.Str +=1
if("Chakra")
src.Chakra +=5
if("HP")
src.HP +=5
switch(input("How would you like to distribute your stat points? You have 8 remaining!","Stats") in list ("Vitality, Strength, Chakra, HP"))
if("Vitality")
src.Vitality +=1
if("Strength")
src.Str +=1
if("Chakra")
src.Chakra +=5
if("HP")
src.HP +=5
switch(input("How would you like to distribute your stat points? You have 7 remaining!","Stats") in list ("Vitality, Strength, Chakra, HP"))
if("Vitality")
src.Vitality +=1
if("Strength")
src.Str +=1
if("Chakra")
src.Chakra +=5
if("HP")
src.HP +=5
switch(input("How would you like to distribute your stat points? You have 6 remaining!","Stats") in list ("Vitality, Strength, Chakra, HP"))
if("Vitality")
src.Vitality +=1
if("Strength")
src.Str +=1
if("Chakra")
src.Chakra +=5
if("HP")
src.HP +=5
switch(input("How would you like to distribute your stat points? You have 5 remaining!","Stats") in list ("Vitality, Strength, Chakra, HP"))
if("Vitality")
src.Vitality +=1
if("Strength")
src.Str +=1
if("Chakra")
src.Chakra +=5
if("HP")
src.HP +=5
switch(input("How would you like to distribute your stat points? You have 4 remaining!","Stats") in list ("Vitality, Strength, Chakra, HP"))
if("Vitality")
src.Vitality +=1
if("Strength")
src.Str +=1
if("Chakra")
src.Chakra +=5
if("HP")
src.HP +=5
switch(input("How would you like to distribute your stat points? You have 3 remaining!","Stats") in list ("Vitality, Strength, Chakra, HP"))
if("Vitality")
src.Vitality +=1
if("Strength")
src.Str +=1
if("Chakra")
src.Chakra +=5
if("HP")
src.HP +=5
switch(input("How would you like to distribute your stat points? You have 2 remaining!","Stats") in list ("Vitality, Strength, Chakra, HP"))
if("Vitality")
src.Vitality +=1
if("Strength")
src.Str +=1
if("Chakra")
src.Chakra +=5
if("HP")
src.HP +=5
switch(input("How would you like to distribute your stat points? You have 1 remaining!","Stats") in list ("Vitality, Strength, Chakra, HP"))
if("Vitality")
src.Vitality +=1
if("Strength")
src.Str +=1
if("Chakra")
src.Chakra +=5
if("HP")
src.HP +=5


Problem description:
Okay its suppose to ask each of these questions in turn, and it works fine until the How old are you question, after they answer, it doesnt continue on to the stat points, I dont see whats wrong. Help Me out?

I'm-a go-ahead and help you just that little bit here.

This code, is terrible, you're using switch() statements, which is a start, but in the end, this is just really, really bad. No offence, but in return for my harsh words, I'm going to help you out just a little.

I personally don't approve of methods like this for a character creation system, I find it ugly and really suggest you look into doing it with the interface. But since you're only learning, I'll cut you a break.

Name: (Procs are fun!)
No goto! goto bad! Rawr! But in all seriousness, goto is considered bad practice and should only be used when absolutely necessary, now isn't necessary. To get around this, you can simply use a proc, and loop it until they provide a name.

proc
set_name()
var/i = input("Please enter a username", "Username") as text
if(!ckey(i)) .()
else return i


This will display an input() for the user and if no text is supplied (if(!ckey(i)) .()) force the prompt to reopen. Please look up '.' in the reference. You'll find it to be very handy down the line. The ckey() check there makes sure the user inserts at least one alphanumeric.




Class: (The switch() is a lie!)
mob
var
class

verb
test()
src.class = input("What class are you?", "Class") in list ("Uchiha","Hyuuga","Inuzuka","Aburame","Akimichi","Uzumaki")
src << "Your class is now: [src.class]"


This will achieve the exact same result as your verb, but kills 99% of the code you're using. I really suggest looking up how input() can be used, you'd be surprised at how easy things can be.




I've given you all you need for Fighter, Style and Age. It's the stat points that you really need to improve on. 99.99% of that code is utterly pointless.

Programming languages contain what we call loops. These loops allow you to repeat superfluous functions multiple times without constant reprogramming. Observe.

mob
var
vitality = 0
strength = 0
chakra = 0
hp = 0

verb
test()
for(var/i = 12; i > 0; i--)
var/stat = input("How would you like to distribute your stat points? You have [i] remaining!", "Stats!") in list("Vitality", "Strength", "Chakra", "HP")
src.vars[ckey(stat)]++
src << "Your [stat] is now [src.vars[ckey(stat)]]"


You'll notice a lot of strange thing sin that.

The vars list is a list of all variables your mob has. I ckey()'d the value of the input() so it'd match the lowercase variable, and then proceeded to add one to it. To take full advantage of that method, you'll have to set up your variables accordingly.

As you can see, with a loop and a bit of ingenuity, you should now have enough to go on to make that code snippet of yours much, much shorter than it is now and infinity better.

I do suggest going over the DM Reference for some tips and tricks like these. They will save you a lot of time in the long run. When you get the time, I suggest looking up the as null|VALUE option for input(), this will add a cancel button automatically to the prompt, so a user can quit out at any time. This means you'll also have to learn how to handle that situation. Something very worth looking into, if you're insisting on keeping this kind of character creation system in the long run.

(To seasoned developers out there: I provided what the user was trying to achieve, not a better looking system. As stated, I hate prompts as creation systems.)
Well, you're saying "Vitality,Strength" instead of "Vitality","Strength", so that's your problem, but seriously, that's one ugly code.

Instead of all the if()'s for clan and age;

usr.clan=input("What class are you?", "Class") in list ("Uchiha","Hyuuga","Inuzuka","Aburame","Akimichi","Uzumaki")

usr.age=input("How old are you?","Age") as num


And instead of all those silly stat point thingies..
var/statpoints=12
while(statpoints)
var/stat=input("Raise what stat? You have [statpoints] stats remaining!","Stats") in list ("Vitality", "Strength", "Chakra", "HP")
var/amount=input("By how much?","Stats") as num
if(amount>0)
usr.vars[stat]+=amount
statpoints-=amount


Note, the statpoint method only works if your vars are named exactly "Vitality" or "Strength". Otherwise you're gonna need text manipulation or if()'s.

Also, for your name selection, it's bad to use 'goto'. A while() will do the trick as well. While the name is too long, too short or unwanted, ask to input a new one.


[Edit]: Damnit Tibby :<
In response to Tiberath
Thanks to both of you guys, you've both been incredibly helpful. I lol'ed @ The switch() is a lie! xD
In response to Tiberath
Tiberath wrote:
proc
> set_name()
> var/i = input("Please enter a username", "Username") as text
> if(!ckey(i)) .()
> else return i


I'm going to join that game, and mash enter til I win.