ID:269406
 
In chatters, when you post code it makes a link you can click and it opens the pop-up window with the code in it, i'm just wondering how do you do make the link part? thanks for any help
WHAT ON EARTH do you mean???

--Vito
In response to Vito Stolidus (#1)
well, i'll try to make it more clear. in chatters, the verb that allows you to chare code, when you click it, type in your code or whatver and press ok, it post a link to the world and if someone clicks it it creates a pop-up, or browser window, that shows the code.... that's probably still not any clearer, but i tried.
In response to Zero's Baby (#2)
xooxer will be the one to ask about that, since Chatters is his baby. i understand it's not a big secret, so he ought to be able to help as soon as he sees this post.
The client/Topic() proc is where most links with byond://? or ? in front of them are sent.


Say you make a link like this:
Link!


You'd need to override client/Topic() like so:
client
Topic(href) // See the reference for argument details
..() // Make sure other calls don't get stalled.
if(href == "my_link")
usr << "You clicked my link!"
// This is one of the rare cases where usr is valid.


If you need more information check the reference.
In response to Nadrew (#4)
I think mob would be a better reference.

client
Topic(href)
..()
var/href_list[] = params2list(href)
switch(href_list["action"])
if("showcode")
var/source = href_list["source"]
var/ID= href_list["ID"]
if(!source || !ID) return
for(var/mob/M in world)
if(M.key == source)
var/html = {"
<html><head>
<title>Showcode Window from
[M.key]</title>
</head><body>
<pre>"}

if(ID in M.showcodes)
html += "[html_encode(M.showcodes[ID])]"
else
html += "This code window has expired."
html += "</pre></body></html>"
mob << browse(html, "window=showcode[source][ID]")
break

mob
var/tmp/list/showcodes
var/const/MAX_SHOWCODES = 5

verb
showcode()
if(!showcodes) showcodes = new
var/code = input("Enter your code:","Showcode") as message | null
if(!code) return
var/ID = "[world.time]"
showcodes.Insert(1, ID)
if(showcodes.len > MAX_SHOWCODES)
showcodes.len = MAX_SHOWCODES
showcodes[ID] = code
var/link = {"<a href='?action=showcode&source=[key]&ID=[ID]'>code window</a>"}
world << "[name]: Click for my [link]."


That's basically how Chatters does it.

~X
In response to Xooxer (#5)
Thanks Xooxer.
I had also been wondering how to go about doing it, and I had tried to use the client/Topic() and I couldn't get it o work. I'll try your way, messing around with it though so I can figure out how it works.
In response to Xooxer (#5)
Oops! Forgot I was using client/Topic() and not CGI/Topic() (where usr is the only valid reference unless you make one yourself). Good catch.
In response to Xooxer (#5)
RyeChat showcode > Chatters showcode

var/list/showcodepages = new



client/Topic(href, href_list[])
..()
switch(href_list["action"])
if("showcode")
var/A = href_list["number"]
A=text2num(A)
if(length(showcodepages)<A) return
src << browse(showcodepages[text2num(href_list["number"])],"window=showcode")

mob
verb
showcode(code as message)
set category = null
src.end_afk()
if(!showcodepages) showcodepages=new
showcodepages.Add({"
<head><title>
[name]'s showcode window</title></head>
<body><pre>
[html_encode("[code]")]</pre></body>"})
src.showcrap("To view my Show-Code Window <a href='?action=showcode;number=[showcodepages.len]'>Click Here!</a>")


Just thought I should tell everyone. -.-

-Ryan
In response to Ry4n (#8)
Unles someone types ?action=showcode&number=0 into their command line, then you'll get a runtime error. :P

And this showcode stuff looks mighty spiffy with Wizkidd0123's DM syntax thingy.

~X
In response to Nadrew (#7)
That's ok. I forgot client/Topic() had 3 arguments, one of them being href_list[]. I didn't need to use params2list() there. :P

~X