ID:141716
 
Code:
var
list/rooms = new

room
var
name
desc
id
New(n)
name = n
rooms += src
id = rooms.len


Problem description:
Well, I'm trying to figure out a way to edit the name in-game by using the id number, or something similar. Could someone help me.
A room manager might be the way to go.

RoomManager
var
list/rooms

New()
rooms = new()

proc
NewRoom(Name, Desc)
var/room/R = new(Name, Desc)
rooms += R

GetRoomByID(RoomID)
if(rooms && rooms.len<=RoomID)
return rooms[RoomID]

GetRoomByName(RoomName)
for(var/room/R in rooms)
if(cmptext(R.name, RoomName))
return R

room
var
name
desc

New(n,d)
name = n
desc = d
In response to Xooxer
Edit*
rooms["name"] = "Untitled"
rooms["id"] = 3
rooms["name"] = "Untitled"
rooms["id"] = 4


What I'm trying to say is, when you create the new room, and set a id and name for it. I wanna be able to go back and edit the name, under that id. So in the example both ID #3 and ID #4 have the name "Untitled". Now if I wanted to edit ID# 3's name and change it from Untitled to Basic Inn, and then edit ID# 4's name and change it from Untitled to Outside. How would I beable to find the IDs and change the names.
In response to Lundex
GetRoomByID() returns a /room datum. Just set the name of the room you get from GetRoomByID().

var/RoomManager/RoomMan // the global room manager

world
New() // when the world starts
..()
RoomMan = new() // create a new room manager

// ... assume you've added bunch of rooms
// to the room manager's rooms list using
// RoomMan.NewRoom(), or else there won't
// be any rooms for the manager to edit :P

proc
EditRoomName(NewName, ID) // ID needs to be a number
var/room/R = RoomMan.GetRoomByID(ID) // find the room
if(R)
R.name = NewName // update the room's name


You could also just add the room editing proc as part of the room manager's functions, or even better, as a function of the room datum itself which you can call from the room manager:

var/RoomManager/RoomMan

world
New()
..()
RoomMan = new()


RoomManager
proc
EditName(newName, ID)
var/room/R = GetRoomByID(ID)
if(R)
R.NewName(newName)

room
proc
NewName(Name)
name = NewName


mob
verb
EditRoomName(newName as text, roomID as num)
RoomMan.EditRoomName(newName, roomID)

In response to Lundex
rooms is a list containing actual rooms. It doesn't directly contain the variables of each room, and DM isn't able to read your mind currently to know which room you are referring to when you do.
In response to Xooxer
You don't actually need to initialize all of your object variables on New() procs, DM supports initializing them on the variable declaration itself to make it easier.
In response to Kaioken
Need? No. Desire? Yes.

You can't control the order of creation, or pass values returned from other objects created if you let DM control the startup. Plus, you can defer creation of objects you won't need right away, so the world loads quicker for the host, if that's an issue. I've learned from people much wiser than myself that initiating variables in the declaration is generally a noobish thing to do. You'll forgive me for listening to them.
In response to Xooxer
Xooxer wrote:
[...] Plus, you can defer creation of objects you won't need right away, so the world loads quicker for the host, if that's an issue.

Correct, but when you are simply immediately creating the object on New(), that's the same thing as initializing it in the declaration, only it takes more work for you and DM.
In response to Kaioken
Why should I care and why are you bringing up DP in CP?
In response to Xooxer
Only one problem, now it only edits the last number. I'm trying to be able to edit all numbers in rooms.
In response to Lundex
No idea what you mean.
In response to Xooxer
Ok, I have a command called redit which redits the name of the room. Syntax is redit <id> <newname>.

Now when I create a new room. I use redit 1 newname to edit the new room's name. Now when I create a new room, I can't edit the last room I created. So I'm trying to figure out how if I create a new room, how I can edit the last room. Because with the current code I can't.