I've been playing with Zilal's text-based MUD tutorial for around two weeks now, and there a couple things I still can't figure out how to do. I want to insert punctuation into the items/mobs/exits here lines of the Room Display proc. I can get it to throw a comma after each item in the room, but how do I make the last one have a period instead?
I was also wondering if anyone could point me in the right direction to start an 'object stacking' system, so if therre were two certificates in a room it would say '2 certificates' instead of certificate twice?
My RoomDisp proc is still pretty much the same as the one in the tutorial, with a few modifications. Heres a snippet of it (the line that displays the items in the room);
src << "Also here: \..."
for(var/mob/M in R) //loops through mobs in room, displaying each
if(M != usr) src << "[M] \..."
src << ""
ID:177999
Jul 1 2002, 1:22 pm
|
|
Jul 1 2002, 2:09 pm
|
|
Err, I have a proc that does just that for my MUD, but I'm not sure I can release it without incuring Spuzzumian wrath.
|
In response to Foomer
|
|
Thats understandable. I'm not really looking for exact code, more like being pointed in the right direction.
My idea for the item stacking would be to make a proc that makes a list of items in the room, each item it add it would check to see if the item is already on the list, if so add 1 to its value, otherwise add it to the list. Then for the puncutation add each item in the list (with a number infront of it if its value is more than 1) with a comma behind it to a single var. Find a way to chop off the last char of the var (the last comma) and add a period. Does that sound do-able, or am I going about it in all the wrong way? If that sounds possible, my only question is how would I remove the last char from a var? Thanks for your help. EDIT - I just started messin around with the idea and I got the puncuation to work nicely, but the item stacking isn't working properly. Heres my proc so far; ObjList(room/R) var/list/items = new for(var/obj/O in R) if(!istype(O,/door)) if(O in items) items[O] += 1 else items[O] = 1 var/product for(var/obj/O in items) if(items[O] == 1) product = "[product] [O]," if(items[O] > 1) product = "[product] [items[O]] [O]," var/N = length(product) product = copytext(product,1,N) product = "[product]\..." return product I haven't used lists much so its probably a stupid error, but atleast the puncuation looks nice; You notice certificate, certificate here. |
Not Tested Tell me if it works.
proc/RoomDisplay()//I am making this for mobso only as ex. for(var/mob/M as mob in room)//room to be considered a datum var/list/L = list() L.Add(M) return list2text(L) proc/list2text(var/list/L) var/loop var/output for(loop as null|anything in L) var/N = L.len for(var/V in loop-L[N]) output += "[V], " output += "[L[N]]" return output return output mob/verb/Look() src << RoomDisplay(blah) It's worth a shot. |
Nice Charman but doesn't look like it will work. Here is an example I made. I hope this helps with RoomDisplay() fit in with code.
proc/sp_list2text(var/list/L) var/output var/loop var/mismatch = L[L.len] for(loop as null|anything in L-mismatch) output += "[loop], " output += "[L[L.len]]." return output mob/verb/Look() var/list/L = list() for(var/mob/M as mob in world) L.Add(M) src << sp_list2text(L) That should give you an idea on how to use my proc I made. Look at what it does ;) Should work effective with list with the same format. |