What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [Question] Randomizing captions

[Question] Randomizing captions
Author: Message:
pollolibredegrasa
Full Member
***

Avatar
formerly fatfreechicken

Posts: 483
Reputation: 34
35 / Male / Flag
Joined: May 2005
O.P. [Question] Randomizing captions
Edit: I meant radio control

Just a quick question (I'm just learning Jscript, so be nice), here's what I have:

1 Window with 4 radio controls defined in my XML file (Resp0, Resp1, Resp2, Resp3)

1 array (thecapt) with 10 strings called ("Blah 1", "Blah 2", "Blah 3", "Blah 4", "Blah 5" etc...)

What I need is to be able to load 4 strings from this array into the 4 radio controls at runtime - at the moment I can load the first 4 strings, however for the script to work the strings from the array need to be randomly selected (and not repeated in another radio control). I don't know how to explain really so heres a kinda example..

Run 1:

    O Blah 1
    O Blah 3
    O Blah 4
    O Blah 2

Run 2:

    O Blah 3
    O Blah 4
    O Blah 2
    O Blah 1

Etc... (each O is supposed to represent a radio control btw)

At the moment the code to fill the radio controls (in order) is as follows:

code:
    iwnd = MsgPlus.CreateWnd("Interface.xml","WndReply")
   
    var i
    for (i=0; i< 4; i++)
    {
        iwnd.SetControlText ("Resp"+[i], thecapt[i])
    }


Any help on how to do this is appreciated, I'm NOT asking you to write the code for me (unless you really want to :P) but any pointers in the right direction as to how to go about this would be appreciated :)

Ps:

I also have this code in the script to generate a random number between 0 and a user defined highest number. Dunno if this is of any use in my problem, but I'll include it here anyway:

code:
function RandNo(TopNo)
{
    return Math.floor(Math.random() * TopNo);
}

This post was edited on 06-29-2006 at 09:30 PM by pollolibredegrasa.
;p

[Image: chickennana.gif] Vaccy is my thin twin! [Image: chickennana.gif]
06-29-2006 07:04 PM
Profile PM Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: [Question] Randomizing captions
The random element will be easy to code: just multiply the result of Math.random() by the length of the array. As for enuring no duplicates, try this:
1. Make a copy of the array, prefereably as a list or set.
2. Select an item from the copy at random.
3. use item.
4. Delete selected item from copy.
5. Repeat from 2.
[Image: spartaafk.png]
06-29-2006 09:39 PM
Profile PM Web Find Quote Report
pollolibredegrasa
Full Member
***

Avatar
formerly fatfreechicken

Posts: 483
Reputation: 34
35 / Male / Flag
Joined: May 2005
O.P. RE: [Question] Randomizing captions
Wow thanks! That method would be great.

One more quick question though, how do you remove a certain item from an array? i.e. after selecting the item at random,  how would I go about removing it from the array?

Thanks for the help :)
;p

[Image: chickennana.gif] Vaccy is my thin twin! [Image: chickennana.gif]
06-29-2006 10:57 PM
Profile PM Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: [Question] Randomizing captions
I don't know about from an array, which is why I suggested a list or set. Not sure if they exist in JScript though: MSDN will have the answers, and if not, Google.
[Image: spartaafk.png]
06-30-2006 11:49 AM
Profile PM Web Find Quote Report
pollolibredegrasa
Full Member
***

Avatar
formerly fatfreechicken

Posts: 483
Reputation: 34
35 / Male / Flag
Joined: May 2005
O.P. RE: [Question] Randomizing captions
Well thanks for the help anyway :)

I loked through the MSDN library and didnt find anything about removing certain items from and array, but found a couple that returns (x) items from whatever start position you choose, as well as one that joins 2 or more arrays.

Using this I created a function that loops through the copy of the array until it finds the item to delete (storing each item in a third, temporary array). Then when it reaches the item to delete, it just adds all the remaining items after that to the temporary array, thus creating a copy of the array with the item removed :d

There are probably more effective methods, but this one seems to work, so I'm happy :)
;p

[Image: chickennana.gif] Vaccy is my thin twin! [Image: chickennana.gif]
06-30-2006 01:43 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On