ID:140861
 
Code:
The roles list
mob
Start_Game
// One question.
// Should the Start_Game verb close off the game to new players?
// Well, I did my job. I have my own game to work on, now. Good luck.
icon = 'StartGame.dmi'
Click()
switch(input("What mode would you like","Modes")in list("Normal","Real World", "Swat", "Zombie mode"))
if("Normal")
NormalMode = 1
if("Real World")
RealWorldMode = 1
if(NormalMode)
AvailableRoles += "L"
AvailableRoles += "Watari"
var/tfm
if(SwatMode || RealWorldMode || NormalMode)
for (tfm=1, tfm<7, tfm++)
AvailableRoles += "Task Force Member"
AvailableRoles += "Chief of Police"
var/po
if(SwatMode || RealWorldMode || NormalMode)
for (po=1, po<4, po++)
AvailableRoles += "Police Offer"
if(NormalMode)
AvailableRoles += "Shinigami"
AvailableRoles += "Shinigami"
AvailableRoles += "Mafia Leader"
var/mm
if(NormalMode || RealWorldMode || SwatMode)
for (mm=1, mm<4, mm++)
AvailableRoles += "Mafia Member"
AvailableRoles += "Double Agent"
var/kf
if(NormalMode|| RealWorldMode)
for (kf=1, kf<4, kf++)
if(NormalMode)
AvailableRoles += "Kira Follower"
AvailableRoles += "STV Manager"
var/stv
if(NormalMode || RealWorldMode)
for (stv=1, stv<4, stv++)
AvailableRoles += "STV Employee"
var/ym
if(NormalMode || RealWorldMode)
for (ym=1, ym<4, ym++)
AvailableRoles += "Yotsuba Member"
AvailableRoles += "Yotsuba Leader"
AvailableRoles += "Detective"
var/pw
if(NormalMode || RealWorldMode)
for (pw=1, pw<4, pw++)
AvailableRoles += "Attorney"
AvailableRoles += "Judge"
AvailableRoles += "Grocery Store Manager"
AvailableRoles += "Electronics Store Manager"
AvailableRoles += "Clothing Store Manager"
AvailableRoles += "Auto-dealership Manager"
AvailableRoles += "Furniture Store Manager"
AvailableRoles += "Pet Store Manager"
var/gse
if(NormalMode || RealWorldMode)
for (gse=1, gse<4, gse++)
AvailableRoles += "Grocery Store Employee"
var/ese
if(NormalMode || RealWorldMode)
for (ese=1, ese<4, ese++)
AvailableRoles += "Electronics Store Manager"
var/cse
if(NormalMode || RealWorldMode)
for (cse=1, cse<4, cse++)
AvailableRoles += "Clothing Store Employee"
var/ade
if(NormalMode || RealWorldMode)
for (ade=1, ade<4, ade++)
AvailableRoles += "Auto-dealership Employee"
var/fse
if(NormalMode || RealWorldMode)
for (fse=1, fse<4, fse++)
AvailableRoles += "Furniture Store Employee"
var/pse
if(NormalMode || RealWorldMode)
for (pse=1, pse<4, pse++)
AvailableRoles += "Pet Store Employee"
AvailableRoles += "Mercenary"
var/fbi
if(NormalMode || RealWorldMode)
for (fbi=1, fbi<4, fbi++)
AvailableRoles += "FBI Agent"
AvailableRoles += "FBI Leader"

// There. Only twenty roles exist now. Now to fix the giving system so tht Kira and L are always given.
//Where is your God, now?
// Uhm. Up.
// Now, should I make it randomly assign everyone a role, and delete your old role if you ahve one? Not a clue. Uhm. Yes?
// Alright, let me think. I know what the problem is. // The problem is.
// For some reason, it reads 'AvailablRoles' as having 0 objects in its list.
//
for(var/mob/Pl in world)
if (Pl.key != null)
if (Pl.Role != "None" && Pl.Role != "Player")
AvailableRoles -= Pl.Role

/*world << "Available Roles:"
var/role
for (b=1, b<c, b++)
role = AvailableRoles[b]
world << "[role]"*/

// So far so good. Wait. I have a question.
// Yes?
// Well, so, does it randomly assign the roles?
// Not yet. I wanted to see if it worked first, by having it display all available roles.
// So, how do we get that to work, persay?
// Like thus:
var/pick
var/outofguys = "No"
var/breakloop = "No"
// What does 'while' do?
// Loop scontinuously while the argument is true.
// In other words, the loop breaks automatically if the argument is no longer true.
// Which, in this cas,e is ehwn there are no more available roles.
// Ah. So, I could use the 'while' proc, instead of the go to' thing for my battle system,
// Mine used 'while' to keep the battle going only while there were two fighters who both wre abl to fight.
// I used goto in it to skip between turns and items and such.
// Ah. Well, so, did that fix it?
// No, it's not done yet.
// Continue
while(breakloop == "No" && AvailableRoles.len > 0)
pick = rand(1, AvailableRoles.len) // Can you gues what this does?
outofguys = "Yes"
for (var/mob/Guy in world)
if (Guy.key != null)
if (Guy.Role == "None")
outofguys = "No"
Guy.Role = AvailableRoles[pick]
if (Guy.Role == "Shinigami")
Guy.invisibility = 1
AvailableRoles -= AvailableRoles[pick]
goto PICKED
PICKED
if (outofguys == "Yes")
breakloop = "Yes"
for (var/mob/Go in world)
if (Go.key && Go.Role != "Player")
var/x = rand(6, 18)
var/y = rand(7, 14)
Go.loc = locate(x, y, 2)
Go.icon = 'CharacterL.dmi'

Ingore the comments
The verb
        ShowRoles()
world<<list2params(AvailableRoles)

Problem description:
The problem is that i want to see if it shows the roles that are available to the world. But it doesn't show anything at all.
Did you know that looping numbers in BYOND with for() can be done much more easily then the standard way (though it is less efficient if I recall correctly but the difference should be negligible for a reasonable # loop).

it goes like this:
for(var/i=1 to 5)
world << i // Will output 1-5

//OR
for(1 to 5) // If you do not care about the # the loop is at

// Another example

for(X to Y) // ex: for(1 to /list.length)



Instead of the following:
                           goto PICKED
PICKED

you should just use break where the goto is. That'll stop (or rather, break) the for() loop.


Ugh! Why don't you group all similar if()s together? Like all the if(NormalMode || RealWorldMode) in one. And you can reuse the same variable! But, if you paid attention to the first snippet I provided, you don't even need that!



Again, if you want to break a loop, use break. Especially in that while. And learn some Boolean tricks as well, they are so ever useful. (Ugh, I wish Bwiki was still here :( ).

Now, is AvailableRoles an initialized globally-defined variable? Did any errors appeared when you tried using the said snippet/verb? Did you tried using length() to make sure that the /list is not empty?
In response to GhostAnime
1. I did not write the roles code i only added the modes code to it.
2. What is the length()?

3.Available roles is a mob list.
In response to Gamemakingdude
1. Ugh, still, that thing is nearly as worse as the DBOZ source (god that still gives me nightmares).

2. length() should be self-explanatory. If it isn't, use the DM Reference (first rule: When dealing with procedures unfamiliar to you, you should check out the DMR first).

3. ...

4. Did you run that verb after starting?
In response to GhostAnime
1. I did run the verb after starting

2.Can you give me an example of lenght()

3. Garthor can you help.
In response to Gamemakingdude
1. M'kay.

2. ...Are you serious? I mean, are you really serious you do not know how to use length()?! Did you even look it up in the DM Reference as I told you to earlier??? They show you how to use it in there (of course replace hi with the variable)!!!!

3. Garthor will help those who he wants to help. >_>'

4. Found the reason why. First of all, I have no idea why you have startgame as a /mob. This is why it made it the problem a bit harder to find.

Since you defined the AvailableRoles variable on a /mob/var, and you did not specified who's variable to modify, it became the default src - which is the mobstart.

In other words, you did define the variable with the values - except not on the object that you wanted it.

You should have referred it to usr (Click() is one of the few safe-spot for use of usr - as long as it is not called indirectly) instead of not having any reference at all, which defaulted to src - which is what you do not want.

Translation of the above: change AvailableRoles --> usr.AvailableRoles
In response to GhostAnime
Ok, Ghost.
I've sent the file to someone with more expertise.
Hopefully he will fix the code and make it more easier and simpler rather than it being jumbled up.