ID:174894
 
How can you check for a name that already exists? Here's an example. Someone comes into the game and makes a guild called "Fighters". Another player wants to make a guild called "Fighters", but when they go to name it, an alert pops up that this guild already exists and that they cannot make the guild as a result.

How can that be done?

-Dagolar
Umm try something like, mob/verb/Guild_Make()
var/Nameit = input("What would you like to name the Guild?")as text
for(var/mob/M in world)
if(M.Guild == Nameit)
alert(src,"This name is taken")
In response to Crashed
That wont work because if a player from a guild isnt on they can still make a guild with the same name...I think the best way is to make a list and whensomeone makes a guild have to check the list to see if the name is taken, if its not taken add it to that list and create the players guild.
Edit: Here's the coding to help you out:
var/list/Guilds = list()
mob
verb
Make_Guild(var/Guildmaking as text)
if(Guilds.Find(ckey(Guildmaking)))
alert("There is already a guild named this. Pick another name.")
else
Guilds += Guildmaking
//Put the make guild coding down here.
Make a list that contains all the guilds in existence (you'll probably want to save that list whenever it changes, and load it at the beginning of the game, but that's a seperate topic)

var/list/guilds = list()

Whenever someone creates a guild, add the guild name to the list. Whenever someone disbands a guild, remove it from the list. Then when someone's creating a new guild, check to see if that guild already exists:

<code>guildname = "Fighters" if(guilds.Find(guildname)) // This guild already exists</code>

Or, if you want to prevent people from getting away with modified punctuation, FiGHtErs, for example, then ckey the name.

<code>if(guilds.Find(ckey(guildname))) // This guild already exists</code>
In response to Koolguy900095
mob
var/list/Guilds = list()

verb
Create_House(var/Guildmaking as text)
set category = "House Commands"
set desc = "What is the name of this House? You can name it after yourself (the leader) or put a theme on it (The Mages of Kreland). MAKE SURE it conforms to the name format, which is: House of (Place House Name Here)."
if(Guilds.Find(ckey(Guildmaking)))
alert("This house already exists. Try a different title.")
else
if(usr.Guild != "")
alert("You cannot create a House while you are in one.")
return
else
usr.Guildnamed = 1
usr.Guildmaster = 1
usr.Guild = Guildmaking
Guilds += Guildmaking


If another person tries to make a guild with the same name, it lets them! Why? It's like it doesn't even get added to the list. How is this much different then what you put?

-Dagolar
In response to Dagolar
you have to add check the ckey() of the guild you are making to the ckey() of a guild in the list
In response to Piccolo-zt
Guilds += Guildmaking


I have it there...What's the problem?

-Dagolar
In response to Dagolar

Index | Preferences | Help
Announcements | BYOND Q&A | BYOND Bugs | Code Problems | Creations | Design Philosophy | Classified Ads | Off Topic | Newbie Central [Advanced Search]

--------------------------------------------------------------------------------

[Messages in this thread] [Show unread (1)]


Author: Dagolar
Date: 7/9/03 10:49 pm
Topic: Name checking - duplicates.
Post [link]
Next [link]


How can you check for a name that already exists? Here's an example. Someone comes into the game and makes a guild called "Fighters". Another player wants to make a guild called "Fighters", but when they go to name it, an alert pops up that this guild already exists and that they cannot make the guild as a result.

How can that be done?

-Dagolar






Author: Crashed
Date: 7/10/03 12:34 am
Topic: Re: Name checking - duplicates.
Post [link]
Parent [link]
Next [link]


Umm try something like, mob/verb/Guild_Make()
var/Nameit = input("What would you like to name the Guild?")as text
for(var/mob/M in world)
if(M.Guild == Nameit)
alert(src,"This name is taken")






Author: Koolguy900095
Date: 7/10/03 1:16 am [Last edited: 7/10/03 1:26 am]
Topic: Re: Name checking - duplicates.
Post [link]
Parent [link]
Next [link]


That wont work because if a player from a guild isnt on they can still make a guild with the same name...I think the best way is to make a list and whensomeone makes a guild have to check the list to see if the name is taken, if its not taken add it to that list and create the players guild.
Edit: Here's the coding to help you out:

var/list/Guilds = list()
mob
verb
Make_Guild(var/Guildmaking as text)
if(Guilds.Find(ckey(Guildmaking)))
alert("There is already a guild named this. Pick another name.")
else
Guilds += Guildmaking
//Put the make guild coding down here.







Author: Foomer
Date: 7/10/03 1:23 am
Topic: Re: Name checking - duplicates.
Post [link]
Parent [link]
Next [link]


Make a list that contains all the guilds in existence (you'll probably want to save that list whenever it changes, and load it at the beginning of the game, but that's a seperate topic)

var/list/guilds = list()

Whenever someone creates a guild, add the guild name to the list. Whenever someone disbands a guild, remove it from the list. Then when someone's creating a new guild, check to see if that guild already exists:

guildname = "Fighters"

if(guilds.Find(guildname))
// This guild already exists

Or, if you want to prevent people from getting away with modified punctuation, FiGHtErs, for example, then ckey the name.

if(guilds.Find(ckey(guildname)))
// This guild already exists






Author: Dagolar
Date: 7/10/03 2:09 pm
Topic: Why doesn't this work....
Post [link]
Parent [link]
Next [link]


mob
var/list/Guilds = list()

verb
Create_House(var/Guildmaking as text)
set category = "House Commands"
set desc = "What is the name of this House? You can name it after yourself (the leader) or put a theme on it (The Mages of Kreland). MAKE SURE it conforms to the name format, which is: House of (Place House Name Here)."
if(Guilds.Find(ckey(Guildmaking)))
alert("This house already exists. Try a different title.")
else
if(usr.Guild != "")
alert("You cannot create a House while you are in one.")
return
else
usr.Guildnamed = 1
usr.Guildmaster = 1
usr.Guild = Guildmaking
Guilds += ckey(Guildmaking)


That should fix.. if not don't yell at me :)



In response to Dagolar
You need to ckey() the guildname when you add it to the list too.

<code>Guilds += ckey(guildname)</code>