ID:140297
 
Hey guys, I'm Stalwart. This may seem kind of beginner to you guys, but could you help me out? I joined BYOND on the 6th of February, by the way.
Code:
mob
Login()
var/nm=rand(1,5)
var/name2=rand(1,5)
if(nm==1)
n1=nm
if(nm==2)
n2=nm
if(nm==3)
usr.n3=nm
if(nm==4)
n4=nm
if(nm==5)
n5=nm
if(name2==1)
a1=name2
if(name2==2)
a2=name2
if(name2==3)
a3=name2
if(name2==4)
a4=name2
if(name2==5)
a5=name2
mob
var
n1 = "Sir"
n2 = "Madame"
n3 = "Lady"
n4 = "Mister"
n5 = "Detective"
a1 = "Forestier"
a2 = "Blah"
a3 = "BYOND"
a4 = "Stalwart"
a5 = "Person"
mob/verb/Name_Check()
usr<<"[nm][name2]"


Problem description:
loading Tests.dme
Tests.dme:16:error: nm: undefined var
Tests.dme:16:error: name2: undefined var

Tests.dmb - 2 errors, 0 warnings (double-click on an error to jump to it)

Things defined in mob/Login() aren't accessible in mob/verb/Name_Check(). In Name_Check(), nm and name2 just don't exist. That's why you're getting a compiler error message telling you they don't exist.

What are you actually trying to do?
In response to Jp
I'm trying to make it that when you login, 2 random names are set for nm and name2.
In response to Stalwart
Learn switch(), look it up in the F1 guide.
In response to Gamemakingdude
Of course, you don't want swtich() here either. You'd want lists and pick().
In response to Gamemakingdude
Learn how to use lists and pick(). Initialize a list of first names and a list for last names. Then, use pick(list) to pick a random element from that list. What you have here can be done in like four lines, if that.

mob/proc/setname()
name=pick(list("Bob","Betty")) + " " + pick(list("Smith","Jones"))


If it's taking you a lot of lines/time to get something like this done, you should look around for alternatives if you are new to the system (there's probably a nicer way of doing it).
In response to EGUY
Oh, I get it. Thank you!
Mob/Login()
var/n=pick("George","Andrew","Kratos","Jimmy","Peter","Carl","Askord","Joćo","Stalin","Bush","Roosevelt","Lula","Saja","Ronaldinho Gaścho")//here you put all your random names
usr.name=n
usr<<"Your name is [usr.name]"

In response to Karffebon
Karffebon wrote:
> Mob/Login()
> var/n=pick("George","Andrew","Kratos","Jimmy","Peter","Carl","Askord","Joćo","Stalin","Bush","Roosevelt","Lula","Saja","Ronaldinho Gaścho")//here you put all your random names
> usr.name=n
> usr<<"Your name is [usr.name]"
>


Really shouldn't be using 'usr' here otherwise you're cruising to develop a bad habit that will later end up in a panicked post on this same forum. Use 'src'.