ID:2164756
 
Hey Guys, I am currently writing a code that allows me to rent and apartment. So far I'm able to pay for the apartment, but I am unsure of how to set area/Apartment Ownership to the usr, and I don't know how to get Ownership verbs for locking the door, etc.

Here is what I have so far.

area/Apartment/var/Price
area/Apartment/var/Owner

mob/var/Ownership

area
Apartment
Home
Apartment1
Price = 100
Apartment2
Price = 150
Apartment3
Price = 300

mob/SuperTenant
icon = 'SuperTenant.dmi'

mob/SuperTenant/verb
Rent()
set src in oview(1)
var/area/Apartment/A=input("Which Apartment would you like to Rent?","Apartment") as null|anything in Apartments
usr << "This Apartment costs [A.Price]."
switch(alert("Are you sure you want to rent it?",,"Yes","No"))
if ("Yes")
usr.Money -= A.Price
A.Owner = usr
usr << "You pay $[A.Price] to rent the apartment for a week."

if ("No")
usr << "Thanks anyways."



area/Apartment/verb/TestOwn() //When I tested this, it says: You don't own this place. which means, I never actually owned it.
set src in view(1)
if (usr == src.Owner)
usr << "You own this place"
else
usr << "You don't own this place"

area/Apartment/proc
Ownership()
set src in view(1) //When I used the TestOwn() verb with (src.Owner != 1) it always said I do own the place, even if I didn't
if (src.Owner != 1)

usr << "You don't own this place"
else
usr << "Congratulations on buying your new home"




area/Apartment/ARVerbs/verb
Lock_Door()
usr << "You lock the door"



var/list/Apartments = list(new /area/Apartment/Apartment1, new /area/Apartment/Apartment2)


area
Apartment
Apartment1
Apartment2
Apartment3


Problem description: I have the option to pick which apartment I want and pay for it, the area of each apartment has been mapped, and that part of the code works... But I don't actually own the apartment and can't use ownership verbs.

Your Apartments list contains area instances that are initialized without a location, so they aren't the same as the areas on the map (See the Reference page for "area").

If you want your Apartments list to refer to the areas on the map, you need to populate it with those areas, which only exist after the map is loaded (which happens after global variables, such as Apartments, are initializing).

Example:
proc // for now, this is a global proc
get_all_apartments()
var global/list/apartments

// generate the list when this proc is called for the first time
// (usually, the first time is after the map done initializing)
if(!apartments)

// option 1: specify all apartments
apartments = list(
locate(/area/Apartment/Apartment1),
locate(/area/Apartment/Apartment2))

// option 2: use all existing apartments
apartments = new
for(var/area/Apartment/apartment)
apartments += apartment

return apartments

Example usage:
input(...) as null|anything in get_all_apartments()