ID:164105
 
I've been messing around with the idea of creating an html based trading system in a pop-up window. Now, I can easily create the href's by simply looping through my inventory, however Im a little stuck with the client/Topic().

What I basically want to know is if there is any shorthand way of doing this, other than looping through all the names and seeing if they match up with the href.

~Zyhtyr.
Instead of using names, you can use references. DM comes with a very neat macro (\ref) that get the "address" of an object and stores it in a string. Therefore, the end output of \ref[some_reference] would look like "[0x30000000]", or something similar to that. To dereference the pointer, you use locate() proc. For your item-picking example, you can use \ref to point to an individual object in your inventory, and use locate() to get the reference of it when it is sent through Topic(). Here is an example from my article (unfortunately, not available at this time).

// The user is able to click the links of any player who is currently logged in the game,
// and see his or her statistics.

mob
var
health
mana
strength

Login()
..()
health = rand(50,100)
mana = rand(50,100)
strength = rand(10,20)

Topic(href, list/href_list)
..()
var/action = href_list["action"]
var/value = href_list["value"]
switch(action)
if("look")
// use locate() to get the reference of the text returned by \ref
var/target = locate(value)
// if it exists (player hasn't logged out after window refreshed), call the look_at() function
if(target) src.look_at(target)
if("close")
// close the window when the player clicks the 'close' button
src << browse(null, "window=playerlist")

proc
look_at(mob/M)
src << "<b>[M]'s stats: </b>"
src << "Health: [M.health]"
src << "Mana: [M.mana]"
src << "Strength: [M.strength]"

verb
list_players()
var/page
var/players

for(var/client/C)
var/mob/M = C.mob
players += \
{"
<tr>
<td width="40%">
[M.name] </td>
<td width="60%">
<a href="byond://?src=\ref
[src]&action=look&value=\ref[M]">
Click to view statistics
</a>
</td>
</tr>
"}


page = \
{"
<html>
<head> <title>Player List</title> </head>
<body>
<b>Players connected:</b>
<table width="100%" border="1">
[players]
</table>
<a href="byond://?src=\ref
[src]&action=close">\[Close Window\]</a>
</body>
</html>
"}

src << browse(page, "window=playerlist&size=500x300")
In response to Unknown Person
Thanks UP, Im pretty sure I can get a clean system working from the info you gave me. Appreciated.

~Zythyr
In response to Zythyr
Ok, I've hit a snag.

mob
Topic(href, list/href_list)
..()
var/action = href_list["action"]
var/value = href_list["value"]
switch(action)
if("drop")
var/target = locate(value)
if(target) Drop_Item(value)

if("close")
src << browse(null, "window=Items")

proc
Drop_Item(obj/O)
src << "You dropped [O]"
O.Move(src.loc)


verb
Trade()
var/page
var/items

for(var/obj/balls/B in src)
items += \
{"
<tr>
<td width="40%">
[B.name] </td>
<td width="60%">
<a href="byond://?src=\ref
[src]&action=drop&value=\ref[B]">
Drop Item
</a>
</td>
</tr>
"}


page = \
{"
<html>
<head> <title>Player List</title> </head>
<body bgcolor=#202020 text=#C9C9C9>
<b><center>Inventory:</center></b><br>
<table width="100%" border="1">
[items]
</table>
<br><center>
<a href="byond://?src=\ref
[src]&action=close">\[Close Window\]</a>
</center>
</body>
</html>
"}

src << browse(page, "window=Items&size=300x300&can_close=0")


I made this drop code to make sure everything would initially work fine, but it doesn't. Im having problems calling the Drop_Item function. As far as I can tell it isn't recognising O as the object, and I get the error -

<font color=red>runtime error: Cannot execute null.Move().
proc name: Trade Item (/mob/proc/Trade_Item)
usr: Dice1989 (/mob/Player)
src: Dice1989 (/mob/Player)
call stack:
Dice1989 (/mob/Player): Trade Item("\[0x2000000]")
Dice1989 (/mob/Player): Topic("src=\[0x3000000]&action=drop&v...", /list (/list))</font>

Again, I'd appreciate any help you can give me to sort this out.

~Zythyr.
In response to Zythyr
Simple careless error: you're using the "value" variable instead of the new type casted and dereferenced variable, "target".
In response to Unknown Person
Ungg...thanks again.