Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / r n d() command

Author
Message
kRx
20
Years of Service
User Offline
Joined: 2nd Apr 2005
Location: Canterbury, Kent, UK
Posted: 11th Aug 2005 17:59
im having some problems with the rnd() code, its getting a random number between 1 and 4 as it should but when for example the random number is 3 i want my character to attack another. the problem is that the number continues to rnaodmise causing my character to flick along the screen as something else happens when the number is 2. is there a way to get around this? thanks in advance

kR

kR
Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 11th Aug 2005 18:21 Edited at: 11th Aug 2005 18:21
inc t
if t=5 then attack=rnd(4) : t=0

"Well if she dies it'll teach her not to do it again..." - Me
Sven B
20
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 11th Aug 2005 19:00
You may only randomize when a certain acion is finished. Else, you'll get the effect you're experiencing.
For example:



I hope it helped

Immunity and Annihalation makes Immunihalation...
kRx
20
Years of Service
User Offline
Joined: 2nd Apr 2005
Location: Canterbury, Kent, UK
Posted: 12th Aug 2005 17:27
hi sven thanks for ur input but im not understanding ur code, could u briefly explain it. mainly the "case 0" and "select attack". thanks

kR

kR
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 12th Aug 2005 18:09
Select case is just an alternative to having lots of IF..Endif statements. For example:

If A=1
Print "1"
Endif
If A=2
Print "2"
Endif
If A=3
Print "3"
Endif

can be replaced by

Select A
Case 1
Print "1"
EndCase
Case 2
Print "2"
EndCase
Case 3
Print "3"
EndCase
EndSelect

In Sven's snippet he was testing the value of the variable attack.

Why didn't you just look this up in the help files?

TDK_Man
kRx
20
Years of Service
User Offline
Joined: 2nd Apr 2005
Location: Canterbury, Kent, UK
Posted: 12th Aug 2005 21:31
i thought he was using select as a random variable

kR
kRx
20
Years of Service
User Offline
Joined: 2nd Apr 2005
Location: Canterbury, Kent, UK
Posted: 14th Aug 2005 00:01
finally got round to researching that and puttin it in my code works perfectly now. forgot to rreinstall the enchancement pack so tose codes wernt avaiable when i posted. thanks a lot guys uve been a great help. it all seems so simple now

kR

kR

Login to post a reply

Server time is: 2025-05-22 13:57:09
Your offset time is: 2025-05-22 13:57:09