Author Topic: Request: Voting script  (Read 2590 times)

James Revan

  • Newbie
  • *
  • Posts: 32
Request: Voting script
« on: March 13, 2008, 08:56:07 AM »
I'm trying to learn how to write scripts but this is still beyond my knowledge. (btw are there any tutorials for IC5 scripting?)

So as the topic says... The script just need 3 options: adding question, adding possible answers, and voting based on host of the users that votes. I run into this kind of script on the irc.onlinegamesnet.net server if someone would want to see how it looks. This is not matter of life and death so if anyone could write it for me (or just give me hints) in spare time, would be great.

Morio

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 256
Re: Request: Voting script
« Reply #1 on: March 13, 2008, 02:27:38 PM »
I think the dictionary object could be used for checking who has voted, and what they have voted

Code: [Select]
dim vote
set vote = CreateObject("Scripting.Dictionary")

Now you have a dictionary. Then yuou could use the ONTEXT sub if you want the votes to be visible to everyone (or ONQUERY if you want it to be private)

When you add stuff to the list the command is basically Object.Add key, item, so this is basically what you'd want

Code: [Select]
'adding stuff to the dictionary:
vote.Add Host, whattheyvoted

The host is the key and 'whattheyvoted' is the item. (The stuff stored to the item should only be the number of the alternative to make it easier to count the votes)

then to prevent them from voting again you could use this:
Code: [Select]
If Not voted.Exists(Host) then
  'code for identifying the vote goes here
End If

Then, when everyone has voted, you could read all the votes into an array like this
Code: [Select]
a = vote.Items
Then you could use the array to get the number of votes each item alternative gets.
Code: [Select]
Alt1 = 0
Alt2 = 0
Alt3 = 0

For i = 0 to vote.Count -1
if a(i) = 1 then Alt1 = Alt1 + 1
if a(i) = 2 then Alt2 = Alt2 + 1
if a(i) = 3 then Alt3 = Alt3 + 1
Next

then after the voting has ended you would use this to clear the dictionary:
Code: [Select]
a = d.RemoveAll
It would be easier to make it only only for yes/no votes, because then you would always have only 2 alternatives, but the code for more alternatives is just a bit more complicated.

Also you could pretty much just copy the code from the '!define' script for the question database
"I don't know what World War 3 will be fought with, but I know World War 4 with be fought with sticks and stones." - Albert Einstein

James Revan

  • Newbie
  • *
  • Posts: 32
Re: Request: Voting script
« Reply #2 on: March 13, 2008, 03:31:08 PM »
Thanks, i'll make a good use of this. And for the question about the tutorials, are there any good ones that i should read?

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: Request: Voting script
« Reply #3 on: March 13, 2008, 06:52:25 PM »
Just check out the help files on the main website, there is a lot of stuff there.
Also available from the Help Menu in the IceChat Editor.
The IceChat God