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 / Random events?

Author
Message
Zeus
19
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 2nd Jan 2009 03:40
I have searched the forums and want to make a random event system for a new top secret project, that is until WIP time. Every now and again I want an event to pop up, example, a statement that says "Joe is hungry." or "Joe is sleepy." at random times. I know it will use variables but that is all I know. Can I have a little help with this?


Thanks,
~Zeus~

Xenxe
17
Years of Service
User Offline
Joined: 25th Dec 2008
Location:
Posted: 2nd Jan 2009 07:00
that would be annoying....

why not have a time system?

random times would mean you could just sleep then be sleepy again :/

but basically this is just theory because im fairly new but what i would do is this

i would assign variables eg hunger

hunger = 0


then i would put somthing in the main loop like

do
inc hunger
if hunger == 100
rem do what you want here
endif
loop


BUT dont take that seriously thats just a poor example but a basic concept of what i would do
NanoGamez guy
19
Years of Service
User Offline
Joined: 13th Jan 2007
Location: Closer than you think...
Posted: 2nd Jan 2009 13:30 Edited at: 2nd Jan 2009 13:34
It depends how random you want it to be.

If you want it to be completely random, you'll need to, every loop, create a variable with a random value and see if it equals, say 0. For example:



Then you'll need a way of choosing which event should happen. All you've got to do is create a random variable which chooses between the number of possible events and use the select command to start the correct event. For example:



However, there is a problem with this way of doing it. Because it checks every loop if an event should happen, there is no set interval between checks. This means that if the FPS (frames per second) is high, the events would occur much more frequently than if the FPS is low, because it loops more often and so checks if the event should happen more often. This is not always a problem, but to get around this, you need to use a timer variable. It is easier to explain with an example:



This checks every loop to see if the time between the last event check and now is more than 250 milliseconds. If it is, it checks to see if the event should happen.

This is all very well if you want the events to happen at purely random times. However if you want the chances of the events happening to increase (e.g. the chances of Joe saying he is hungry to increase as he gets more hungry), then you need to use a different system. Basically you just change the chances of the event happening by changing the number in the brackets of the rnd() command based on a variable. If you want the chances to increase as a variable decreases (e.g. the chances of Joe saying he is tired increasing as the energy variable decreases) you just need to put that variable in the brackets of the rnd() command (as long as the variable is positive). If you want the chances of an event happening to increase as a variable increases (e.g. the chances of Joe saying he is hungry increasing as the hunger variable increases), you'll put the maximum value of that variable minus the value of the variable in the brackets of the rnd() command. (e.g. rnd(100-hunger)). For example:




"There is no charge for awesomeness" - The Kung Fu Panda
Zeus
19
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 3rd Jan 2009 04:03
Thank you that is perfect.

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 3rd Jan 2009 18:16
Quote: "if rnd(maxhunger-hunger)=0"


pretty slick!

Don`t forget to use "randomize timer()" to set the seed according to the current time, which is pretty random.

TheComet

Peachy, and the Chaos of the Gems

Login to post a reply

Server time is: 2026-07-05 01:48:04
Your offset time is: 2026-07-05 01:48:04