Page 1 of 1 1
Topic Options
#136384 - 2005-03-25 06:51 PM Play a random sound in script
Anonymous
Unregistered


$listen = rnd(20) + ".wav" does not work

If I do:

$number_to_use = rnd(20)
$final_crap = $number_to_use = ".wav"

This does not work either. What stupid thing am I overlooking?


Top
#136385 - 2005-03-25 06:56 PM Re: Play a random sound in script
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
It has to do with the way arithmetic and string math works, you did this:

$listen = rnd(20) + ".wav"

which tells Kixtart to add a Number to a String, the number is specified first therefore kixtart will try to convert the result to a Number, if you do this:

$listen = "" + rnd(20) + ".wav"

this does the same thing, except the "" is first and tells Kixtart to convert the result to a String, which is what you really want. Could also say:

$listen = CStr(rnd(20)) + ".wav"

-Shawn

Top
#136386 - 2005-03-25 07:06 PM Re: Play a random sound in script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
Quote:

which tells Kixtart to add a Number to a String



vice versa.
_________________________
!

download KiXnet

Top
#136387 - 2005-03-25 07:07 PM Re: Play a random sound in script
Anonymous
Unregistered


Shawn you rock. Thanks for taking the time!
Top
#136388 - 2005-03-25 07:33 PM Re: Play a random sound in script
Anonymous
Unregistered


Hey thanks a lot Shawn! - You rock.

I appreciate it.. Don't know how I missed CStr!!

Top
#136389 - 2005-03-25 08:05 PM Re: Play a random sound in script
Anonymous
Unregistered


ok now I can't get a random number
#135666 - 25/03/2005 19:58
Edit post Edit Reply to this post Reply Reply to this post Quote Quick Reply Quick Reply

SRND( @MSECS )
$listen = CStr(rnd(20)) + ".wav"
at (12,16) @MSECS

On my machine @MSECS *always* - 250 or 218
Which means my wav file will always be 0.wav

Harumph.

Top
#136390 - 2005-03-25 08:12 PM Re: Play a random sound in script
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Try this

SRND(IIF(@TICKS<0,(-(@TICKS)),@TICKS))

?"VALUE=" RND(100)
?"VALUE=" RND(100)
?"VALUE=" RND(100)

Might even want to retrieve and discard, the very FIRST RND(), which based on past experienced is always less than totally random.


-Shawn

Top
#136391 - 2005-03-25 09:34 PM Re: Play a random sound in script
Anonymous
Unregistered


Sweeet that works very well.

Now I can bombard my uses with random sounds (36 of them) every time they sign in. Clips from "Kelly's Heros" seem to work quite well

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1188 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.058 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org