ID:161351
 
Hello there! =)

var/list/queue = list()
// This list contains mobs.

proc/VoteCasting()
// This is what I'm looking for!

proc/StartRound()
world << "Round is starting..."
// Many things happen in here.
world << "Time is over-- prepare to vote!"
sleep(20)
VoteCasting()


I'm wondering if it is possible to make it so that, the procl oops through every mob in queue(), and creates a pop-up window for each one of them-- and after a certain ammount of time, the alert boxes will close on the people who did not vote.

Was I clear enough?
Thanks for reading!

~Gooseheaded
This is what I wrote a while ago:

//a new data type, representing a vote
vote
//whether or not votes are announced:
var/secret = 0
//list containing the valid options for voting:
var/list/options = list()
//associative list of keys who have voted, along with their votes
var/list/votes = list()
//this is the proc that will handle link clicks
Topic(href, href_list[])
//get the key of the client who is voting
var/voter = usr.key
//get their vote
var/vote = href_list["vote"]
//ensure that it's a valid vote
if(!(vote in options))
usr << "That is not a valid option!"
return
//(this should only happen if the player is intentionally attempting to mess with the vote)

//check to see if they've already voted
if(votes.Find(voter))
//they've voted the same thing twice
if(vote == votes[voter])
usr << "You've already voted \"[vote]\"!"
//changing vote
else
usr << "You change your vote to \"[vote]\""
if(!secret)
world << "[voter] changed their vote to \"[vote]\""
//new vote
else
usr << "You vote \"[vote]\""
if(!secret)
world << "[voter] votes \"[vote]\""

//register the vote
votes[voter] = vote

//to start the vote:
proc/startVote(var/query, var/list/options, var/duration = 600, var/secret = 0)
src.options = options
src.secret = secret

//announce the vote
world << "A vote has been started:"
//announce the query
world << query
//announce the options
var/n = 0
for(var/option in options)
n++
world << "[n]) <a href='?src=\ref[src];vote=[option]'>\"[option]\"</a>"
world << "The vote will end in [duration/10] seconds."

//wait for people to vote
sleep(duration)

//tally the results
var/list/results = options.Copy()
//initialize the list properly
for(var/option in results)
results[option] = 0
//go through the votes
for(var/voter in votes)
//get their vote
var/vote = votes[voter]
//add their vote to the results
results[vote]++

//now we have to loop through the results to find the winner (sigh)
//we'll display the votes as we go along, though
var/winner = ""
var/winningvotes = 0
world << "The vote has ended!"
world << query
for(var/vote in results)
world << "[results[vote]]: \"[vote]\""
//check if it's the winner so far
if(results[vote] > winningvotes)
//note: a tie is resolved by the vote that is presented first winning
winner = vote
winningvotes = results[vote]
world << "The consensus is \"[winner]\""

//finally, return the results of the vote:
return winner

//This proc will create a vote object and use it to start a vote, then return the result of it
proc/startVote(var/query, var/options, var/duration = 600, var/secret = 0)
var/vote/v = new()
var/result = v.startVote(query, options, duration, secret)
del(v)
return result


It shouldn't be too difficult to adapt that.
In response to Garthor
Well, I was just about to write a /vote datum as well, but this works. Something you should've mentioned was that a system to close alert() windows is completely impossible, and he'll have to user the interface for that.
In response to Popisfizzy
Garthor had done what I described, a while ago.
I rememeber that he, somehow, used the proc as a var, or something similar.

Thanks for reading, though!
In response to Garthor
You rock ;)
In response to Popisfizzy
You can close alert() and input() windows by deleting the object which called them. The vote objects are explicitly deleted when the vote is over, so just cramming alert()s in there should work.
In response to Popisfizzy
completely impossible.. heheheh...
It's never too late to learn something new, eh? =)
In response to Garthor
Hmm, wow, I didn't know that. I wish we still had someplace to document the undocumented behavior like this but, alas, the Bwicki is gone.
In response to Garthor
After a voting sessions is done, are these links "deleted" or "canceled" in some way?

Because I'm running this code several times, and the voting options will repeat.
In response to Popisfizzy
Popisfizzy wrote:
Hmm, wow, I didn't know that. I wish we still had someplace to document the undocumented behavior like this but, alas, the Bwicki is gone.

Oddly enough, it was well documented in the Bwicki before it was removed.
In response to Gooseheaded
Ooh, that makes me realize that references are reused, so you end up with an old link pointing to a new vote object. That shouldn't be too difficult to solve, though.

//a new data type, representing a vote
vote
//number of vote datums that have been created
var/global/numvotes = 0
//id of this vote, to ensure old links don't work
var/id
//whether or not votes are announced:
var/secret = 0
//list containing the valid options for voting:
var/list/options = list()
//associative list of keys who have voted, along with their votes
var/list/votes = list()

//initialize the vote object properly
New()
..()
//we need to keep track of which vote this is, as old links will point to new votes
id = "[numvotes]"
numvotes++

//this is the proc that will handle link clicks
Topic(href, href_list[])
//ensure the id of the link and this vote object match
if(href_list["id"] != id)
return
//get the key of the client who is voting
var/voter = usr.key
//get their vote
var/vote = href_list["vote"]
//ensure that it's a valid vote
if(!(vote in options))
usr << "That is not a valid option!"
return
//(this should only happen if the player is intentionally attempting to mess with the vote)

//check to see if they've already voted
if(votes.Find(voter))
//they've voted the same thing twice
if(vote == votes[voter])
usr << "You've already voted \"[vote]\"!"
//changing vote
else
usr << "You change your vote to \"[vote]\""
if(!secret)
world << "[voter] changed their vote to \"[vote]\""
//new vote
else
usr << "You vote \"[vote]\""
if(!secret)
world << "[voter] votes \"[vote]\""

//register the vote
votes[voter] = vote

//to start the vote:
proc/startVote(var/query, var/list/options, var/duration = 600, var/secret = 0)
src.options = options
src.secret = secret

//announce the vote
world << "A vote has been started:"
//announce the query
world << query
//announce the options
var/n = 0
for(var/option in options)
n++
world << "[n]) <a href='?src=\ref[src];id=[id];vote=[option]'>\"[option]\"</a>"
world << "The vote will end in [duration/10] seconds."

//wait for people to vote
sleep(duration)

//tally the results
var/list/results = options.Copy()
//initialize the list properly
for(var/option in results)
results[option] = 0
//go through the votes
for(var/voter in votes)
//get their vote
var/vote = votes[voter]
//add their vote to the results
results[vote]++

//now we have to loop through the results to find the winner (sigh)
//we'll display the votes as we go along, though
var/winner = ""
var/winningvotes = 0
world << "The vote has ended!"
world << query
for(var/vote in results)
world << "[results[vote]]: \"[vote]\""
//check if it's the winner so far
if(results[vote] > winningvotes)
//note: a tie is resolved by the vote that is presented first winning
winner = vote
winningvotes = results[vote]
world << "The consensus is \"[winner]\""

//finally, return the results of the vote:
return winner

//This proc will create a vote object and use it to start a vote, then return the result of it
proc/startVote(var/query, var/options, var/duration = 600, var/secret = 0)
var/vote/v = new()
var/result = v.startVote(query, options, duration, secret)
del(v)
return result