ID:261821
 
I was looking for tutorials and demos and references and source codes and something that could help me get through this alert/list/switch code problems I've been trying to get through for the past couple of days. And I think I found something good, though I'm having some trouble. Here's the code for it:

    var/list/jobs = new()
jobs += "Black Mage"
jobs += "White Mage"
jobs += "Red Wizard"
jobs += "Fighter"
jobs += "Monk"

var/job = input("What job class do you want?","Choose job class.", null) in races
var/job/new_mob
switch(job)

if ("Black Mage") new_mob = new /Mobs/Jobs/Black Mage()
if ("White Mage") new_mob = new /Mobs/Jobs/White Mage()
if ("Red Wizard") new_mob = new /Mobs/Jobs/Red Wizard()
if ("Fighter") new_mob = new /Mobs/Jobs/Fighter()
if ("Monk") new_mob = new /Mobs/Jobs/Monk()


(I think the indents got messed up.)

And here're the errors:

Logging In stuffs.dm:49:error: Mage: expected end of statement
Logging In stuffs.dm:50:error: Mage: expected end of statement
Logging In stuffs.dm:51:error: Wizard: expected end of statement

Those are for the end of the new_mob = new line. I'm not sure what the problem here is. Help would be appreciated. Thanks.
Use underscores ( _ ) instead of spaces in your object names.
In response to Garthor
O.O;;

When I do that, I get this error:

ogging In stuffs.dm:45:error:races:undefined var
Logging In stuffs.dm:49:error:new_mob:undefined type: new_mob
Logging In stuffs.dm:49:error:/Mobs/Jobs/Black_Mage:undefined type path
Logging In stuffs.dm:50:error:new_mob:undefined type: new_mob


But I get 14 of them, I get that for each job class. Should I change the .dmi names so there's no spaces or so that there's an underscore included in them?
In response to Rockin' Eli
Well your problem is you're using type paths you never defined. Is there a /Mobs/Jobs/Black_Mage definition in your code?
In response to Garthor
No.. No I don't think so. I thought that's what this part was:
var/list/jobs = new()
jobs += "Black Mage"
jobs += "White Mage"
jobs += "Red Wizard"
jobs += "Fighter"
jobs += "Monk"


I guess not, though.

Could you give me an example?
In response to Rockin' Eli
Nope, that just creates a global list called "jobs" and sticks a bunch of strings in it. To actually create a type path, you have to do something like this:

<code>mob Jobs Black_Mage //Now you've defined the type of mob, set its vars etc. icon='blackmageguy.dmi' icon_state="evil" Login() ..() world << "[src], a Black Mage, has just logged in. Fear their darkness!"</code>

The "mob/Jobs/Black_Mage" bit actually defines the type path. The rest of it just does stuff with vars and procs, making the Black_Mage different from other types of mobs.
In response to Crispy
Whoaaaa, I must've done somehting wrong now.

This is the whole code now:

mobs 
jobs
Black_Mage
icon = 'BlackMage.dmi'
White_Mage
icon = 'WhiteMage.dmi'
Red_Wizard
icon = 'RedWizard.dmi'
Thief
icon = 'Thief.dmi'
Fighter
icon = 'Fighter.dmi'
Monk
icon = 'Monk.dmi'

var/jobs = input("What job class do you want?","Choose job class.", null) in jobs
var/jobs/new_mob
switch(job)

if ("Black_Mage") new_mob = new /mobs/jobs/Black_Mage()
if ("White_Mage") new_mob = new /mobs/jobs/White_Mage()
if ("Red_Wizard") new_mob = new /mobs/jobs/Red_Wizard()
if ("Thief") new_mob = new /mobs/jobs/Thief()
if ("Fighter") new_mob = new /mobs/jobs/Fighter()
if ("Monk") new_mob = new /mobs/jobs/Monk()


(This must be annoying you smart coding people as much as it's annoying me.)

Now.. I have about 30 errors. Here:

---------

Logging In stuffs.dm:64:error:new_mob:undefined type: new_mob
Logging In stuffs.dm:64:error::duplicate definition
Logging In stuffs.dm:59:error::empty type name (indentation error?)
Logging In stuffs.dm:55:error:jobs: compile failed (possible infinite cross-reference loop)

---------

Logging In stuffs.dm:52:error:icon:undefined var
Logging In stuffs.dm:56:error:job:value not allowed here
Logging In stuffs.dm:58:error:"Black_Mage":duplicate definition

---------

Just so you know, I got about 6 of each of those errors, so I'm guessing that the mistake is repeated for each of the class. So I'm guessing if I can just get the answer to one of those errors, I can fix all of them, at least I'd like that.. Hoping someone can help.. Thanks..
In response to Rockin' Eli
var/mob/jobs, not var/jobs.
In response to Garthor
Sweet deal, that got rid of about 7 errors. I still have the duplicate definition errors, about 14 of them, which I don't understand, considering there's no duplication going on. And I got an empty type name error which I never heard of, jobs compile failed error (possible infinite loop cross reference), whatever that means, and a bunch of undefined variable code errors. Which variable is it talking about? I thought I defined the variable here:

var/mobs/jobs = input("What job class do you want?","Choose job class.", null) in jobs
var/mobs/jobs/new_mob
switch(job)


Thank you.
In response to Rockin' Eli
Rockin' Eli wrote:
mobs

First problem. It's "mob", not "mobs". You've repeated this mistake several times throughout the code.

jobs
Black_Mage
icon = 'BlackMage.dmi'
White_Mage
icon = 'WhiteMage.dmi'
Red_Wizard
icon = 'RedWizard.dmi'
Thief
icon = 'Thief.dmi'
Fighter
icon = 'Fighter.dmi'
Monk
icon = 'Monk.dmi'

From here on, there's a big problem. You're putting in code that belongs in a proc, but you haven't actually put it in a proc. This usually causes Dream Maker to go crazy with thousands of error messages.

You're also mistaking a type declaration with a list. When you say "in jobs" below, "jobs" must be a list. But unless you haven't shown the definition for the "jobs" list, it looks like you're trying to get all the "jobs" types. Which won't work the way you've done it.

You can still use a "jobs" list, but you have to actually make it. For example:

<code>var/jobs[]=list("Black_Mage", "White_Mage", "Red_Wizard", "Thief", "Fighter", "Monk")</code>

var/jobs = input("What job class do you want?","Choose job class.", null) in jobs

The "infinite cross-reference loop" error is due to this line. You're defining "jobs" in terms of "jobs". That's like saying in algebra that "x is equal to x" and expecting to get the actual value of x from that. =) You need to define it as "job" rather than "jobs". This is more of a typo than anything. =)

var/jobs/new_mob

This should be "var/mob/jobs".

switch(job)

if ("Black_Mage") new_mob = new /mobs/jobs/Black_Mage()
if ("White_Mage") new_mob = new /mobs/jobs/White_Mage()
if ("Red_Wizard") new_mob = new /mobs/jobs/Red_Wizard()
if ("Thief") new_mob = new /mobs/jobs/Thief()
if ("Fighter") new_mob = new /mobs/jobs/Fighter()
if ("Monk") new_mob = new /mobs/jobs/Monk()</dm>

Almost fine, except you've again put "mobs" instead of "mob".

Hopefully that fixes all of your errors. If not, post the revised code and the remaining errors.
In response to Crispy
Well, this all makes good sense.. But, I still have about 20 duplication errors now, this might be because I still haven't put in a proc(). I didn't put one in yet mainly because I don't understand how. Would the proc be something like this?
mob
var/mob/jobs

proc/Jobs(J)
if("Red_Wizard")
icon = 'Red_Wizard.dmi'


Yeah... Yeah I have no idea how to make a proc().

I'm getting a jobs previous definition and empty type name now with the list in there.