ID:179145
 
how do i make it so when a user can browse a list in the browser?

I made my list like this.
var/list/Q   // world list

world/New()
Q = list()
..()

mob/proc/MC()
if(Q.len==10)
Q.Cut(1,2) //snip out the first list item

and to view the list i made a verb.
mob/verb/ChatShow()
for(var/obj/O in Q)
usr << browse(
{"
<table background="black" border width="100%"><TR>
<td bgcolor="Black" width="95%"><p align="center"><font color="white">The List!</font></p></td></tr></table>

<table background="black" border WIDTH="100%">
<tr>
<td bgcolor="Black" width="80%">
[O]</td></tr></table>
"}
)

When they click the verb. it doesnt show the list in the browser. what did i do wrong?
There's nothing in the list...
In response to Foomer
yes i thought about that too, so it should still show the words "The List" but the browser doesnt even open
In response to dbz73
Nope, becuase of the for loop. Your telling the game to display your html for each object in the list. Becuase you have no objects in that list, it displays nothing. By the way, if you did put more than one object in that list, it would re-display your table for each item. Probably not what you want:

The List

a cabbage

The List

rope

The List

a dagger

~X
In response to Xooxer
err O.O thats not what i wanted, but yea, even when there is something in the list, it doesnt show up
In response to dbz73
Are you sure you put an obj in the list?

for(var/obj/O in Q)

Your verb won't display anything unless it's an obj.

~X
In response to Xooxer
err this is how i have stuff be put in a list
mob/verb/blah(T as text)
var/M="<font color=blue>< </font>\
<font color=white>
[usr]</font><font color=blue> > \
<font color=white>
[copytext(html_encode(T),1,250)]</font><br>"
FloodBlock()
FloodCheck()
Q+=M
MC()

Im not sure what that would be so i guessed.
In response to dbz73
dbz73 wrote:
err this is how i have stuff be put in a list

mob/verb/blah(T as text)
var/obj/M="bla bla bla.."

Im not sure what that would be so i guessed.

You're adding a var to the list, but you're trying to display an obj var when you call ChatShow(). Try adding in what I have put in bold above, and see if that helps.

~X
In response to Xooxer
ok i did that, but the browser still isnt showing up.
In response to dbz73
Ok then, I copied your code into Dream Maker, and fiddled with it a bit. Here's what I have, and it displays properly in the browser:

var/list/Q   // world list

world/New()
Q = list()
..()

mob/proc/MC()
if(Q.len==10)
Q.Cut(1,2) //snip out the first list item



mob/verb/ChatShow()
for(var/O in Q)
usr << browse(
{"
<table background="black" border width="100%"><TR>
<td bgcolor="Black" width="95%"><p align="center"><font color="white">The List!</font></p></td></tr></table>

<table background="black" border WIDTH="100%">
<tr>
<td bgcolor="Black" width="80%">
[O]</td></tr></table>
"}
)

mob/verb/blah(T as text)
var/M="<font color=blue>< </font>\
<font color=white>
[usr]</font><font color=blue> > \
<font color=white>
[copytext(html_encode(T),1,250)]</font><br>"
Q+=M
MC()


I removed the obj from your ChatShow() verb and the obj I had you add to the blah() verb. I don't think this is the behavior you're looking for, but it now opens the browser window and displays you HTML along with whatever was inputed through the blah() verb.

~X
In response to Xooxer
Ok that helped a lot, but now it only will show one thing that was put in. like lets say you put in "meh" and then "mah" only meh will show up
In response to dbz73
It's because you're browsing for every thing in the list, meaning it opens a new page for each item, so it will display the last thing in the list.
In response to Nadrew
how do i make it so it all shows up on one page?
In response to dbz73
dbz73 wrote:
how do i make it so it all shows up on one page?

Basically this is a similar problem to your other post. You've got something inside the loop that belongs outside. Generally when you put lists in HTML, you'll do it like this:
var/txt="<HTML>"
for(thing in thelist)
txt+="[thing]\n"
txt+="</HTML>"
player << browse(txt)

So you see, the list should add text to your eventual output. Alternatively, you could make a proc to return a text/HTML string, and insert it into your browse() code this way:
player << browse("<HTML>[ListToHTML(thelist)]</HTML>")

In most of my routines that create HTML for output to a user, I also send the mob as an argument so I can use browse_rsc() to preload graphics.

Lummox JR
In response to dbz73
Add it to another list of course:

var/Q = new()

world/New()
Q = list()

mob/verb/TestThing()
var/list/Newitems = list()
for(var/O in Q)
Newitems.Add(O)
usr<<browse("[Newitems]")



(Untested)
In response to Nadrew
Nadrew wrote:
Add it to another list of course:
var/Q = new()

world/New()
Q = list()

mob/verb/TestThing()
var/list/Newitems = list()
for(var/O in Q)
Newitems.Add(O)
usr<<browse("[Newitems]")

(Untested)

As a person who's tried to use "[list]" before, I can tell you with certainty that that won't work. But since it doesn't have any HTML headers or footers, this would be inappropriate for browse() anyway. What dbz73 needs to do is think of this in terms of building an HTML document piece by piece, then sending it out.

Lummox JR
In response to Lummox JR
Ok i did the list to html thing. and i got this error

BrowserChat.dm:65:error:ListToHTML:bad proc

This is how i did it, i might have done it wrong.

/proc/blah()
if(usr.Blee==1)
usr << browse(
{"<body background=black color=white>
[ListToHTML(Q)]"})
In response to Lummox JR
browse() has the headers, and footers built in.
In response to dbz73
dbz73 wrote:
Ok i did the list to html thing. and i got this error

BrowserChat.dm:65:error:ListToHTML:bad proc

Well that's because you didn't write that proc. I was just showing you an example.

Lummox JR
In response to Lummox JR
how would i go about writing that proc?