Random numbers and if..then..else conditions

Questions about how to create your own dungeons and replacement graphics and sounds.

Moderator: George Gilbert

Forum rules
Please read the Forum rules and policies before posting.
Post Reply
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Random numbers and if..then..else conditions

Post by Gambit37 »

Is it possible to generate random numbers using RTC, take that value and shove it in a counter for use later?

Is it possible to do if..then..else conditioning. The relays work great for if...then, but don't offer an alternate action if the condition isn't met.

I tried having two relays triggered at the same time, one with an "equal to" condition and with a "not equal to", but obviously this isn't the same thing.
User avatar
Black Eagle
Journeyman
Posts: 76
Joined: Mon Jan 28, 2008 10:58 pm
Location: Leicester, UK

Post by Black Eagle »

not sure about random numbers but i find gigglers in locked rooms are just as random and have helped me out many a time!
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Post by Gambit37 »

Ah, good old gigglers, I didn't think of that method. With all the new actions and stuff in RTC, I was thinking in advanced mechanics terms, but the giggler might actually be better.

Having said that, the above stuff would still be incredibly useful.
User avatar
Lord_BoNes
Jack of all trades
Posts: 1064
Joined: Mon Dec 01, 2008 12:36 pm
Location: Ararat, Australia.

Post by Lord_BoNes »

I fully agree Gambit. RTC needs an else condition for relays. Having to put in twice as many relays just to achieve an else branch of things is quite a hog.
 
Image

1 death is a tragedy,
10,000,000 deaths is a statistic.
- Joseph Stalin

Check out my Return to Chaos dungeon launcher
And my Dungeon Master Clone
User avatar
Simplicus
Neophyte
Posts: 9
Joined: Fri Jul 24, 2009 11:27 pm
Location: Dallas, TX USA

Re: Random numbers and if..then..else conditions

Post by Simplicus »

Could you please explain the Giggler method?

Thanks,

Simplicus
__________________________________________
300,000 Kilometres/Sec. Not just a good idea, it's the law!
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Random numbers and if..then..else conditions

Post by Gambit37 »

You put a giggler in a stand alone room with floortriggers all over it. Set the triggers to set a counter value, or whatever you want to do.
User avatar
Simplicus
Neophyte
Posts: 9
Joined: Fri Jul 24, 2009 11:27 pm
Location: Dallas, TX USA

Re: Random numbers and if..then..else conditions

Post by Simplicus »

Ah, excellent. I have used slow moving monsters in such rooms to randomly open and close traps and toggle movable walls. This adds another dimension... Thanks,

Simplicus.
__________________________________________
300,000 Kilometres/Sec. Not just a good idea, it's the law!
User avatar
beowuuf
Archmastiff
Posts: 20687
Joined: Sat Sep 16, 2000 2:00 pm
Location: Basingstoke, UK

Re: Random numbers and if..then..else conditions

Post by beowuuf »

csb is filled with odd tricks like this, so it seemed like a new engine!
Was unable to (permenantly) kill off ian_scho (Haynuus), Ameena, oh_brother (Westian), money (Falkor), raixel (Petal) and Lord_Bones (Aurek) in the DM D&D game Time's Champions!

CONGRATULATIONS TO THOSE WHO MADE THE GAME WHAT IT WAS - GREAT!
User avatar
Lord_BoNes
Jack of all trades
Posts: 1064
Joined: Mon Dec 01, 2008 12:36 pm
Location: Ararat, Australia.

Re: Random numbers and if..then..else conditions

Post by Lord_BoNes »

To achieve a random number effect.
EG: 1-5.... Have a relay trigger another relay that has a 20% to activate 5 times, then compare its value. You have to reset the counter afterwards, so you can use it again, to do this...
Have a relay that triggers the counter and itself (make sure it triggers itself last, the bottom of the list) then just give the relay a "if counter greater than 0" condition, and the counter will set itself to 0 whenever the relay is triggered. You can do the same with "if counter less than <value>" you make the looping relay trigger another relay the deactivates the counter instead. Hope I've shed some enlightenment :P
 
Image

1 death is a tragedy,
10,000,000 deaths is a statistic.
- Joseph Stalin

Check out my Return to Chaos dungeon launcher
And my Dungeon Master Clone
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Random numbers and if..then..else conditions

Post by Gambit37 »

This makes no sense, your language isn't clear. "Have a relay trigger another relay that has a 20% to activate 5 times, then compare its value" Sorry, I just don't understand what that means!

Can you put that in straightforward steps, in context of how you'd build it in the editor? Some of us here simply don't think the way that programmer types do, so generalising logic problems into ambiguous language simply doesn't help.

Welcome back by the way :)
User avatar
Lord_BoNes
Jack of all trades
Posts: 1064
Joined: Mon Dec 01, 2008 12:36 pm
Location: Ararat, Australia.

Re: Random numbers and if..then..else conditions

Post by Lord_BoNes »

1. Create a relay (henceforth called "RELAY1").
2. Create another relay (henceforth called "RELAY2")
3. Set "RELAY1" target to "RELAY2" x4 (you want x4 because you may not have any manage to hit the 20% chance, so 0 is a possible result), so 4 duplicate target entries, and action to activate.
4. Set "RELAY2" probability chance to 20% (100% divided by desired number of random possibilities, 5 in this case so 100/5 = 20%), and action to deactivate.
5. Create a counter. Leave counter value at 0, with no targets. Set "RELAY2" target to the newly created counter.
At this point, when you trigger "RELAY1", the counter will end up on a random number between 0 and 4 (20% chance on each activation of "RELAY2" to deactivate or INCREMENT the counter).

Now you need to check the value of the counter... to do this you create 5 new relays with each relay's condition being a value from 0-4. Add these new 5 relays to the target list for "RELAY1", but make sure it's after "RELAY2" is triggered (so "RELAY2" at the top of the list). Have each of the 5 relays do what you wish for the particular value... so you might have the value 0 move an object, while the value 1 might move a different object.

As I have been typing this I realised that I'd made a small error in the above post, the value 0 is a possible outcome, so you need to check for the values from 0 to the desired number-1.

Now, in the above post, I tried to explain how to reset the counter...
6. Create a new relay (henceforth called "RELAY3").
7. Set "RELAY3" first target to the counter, and set the second target to "RELAY3" (yes, itself)... now, change the condition to check if the counter's value is greater than 0.
The way this works: the "RELAY3" triggers, checks its condition (is counter > 0)... if so, it activates the counter (which decrements the value) then it activates itself, does its check again, decrements counter again.... etc.... until the counter is 0.
I also mentioned how to do the reverse function (is counter < 0 then increment).... create yet another #$%&ing relay set its target to the counter, and its action to deactivate. Then just change the first target for "RELAY3" from the counter, to this new relay. Then change the "greater than" condition to "less than".

Sorry for the lack of explaination above, but it is 7am here, and I'm getting abit on the tired side :P
Last edited by Lord_BoNes on Sat Aug 08, 2009 9:35 am, edited 1 time in total.
 
Image

1 death is a tragedy,
10,000,000 deaths is a statistic.
- Joseph Stalin

Check out my Return to Chaos dungeon launcher
And my Dungeon Master Clone
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Random numbers and if..then..else conditions

Post by Gambit37 »

Uh, right, think I'll come back to this one day when I can't get to sleep! ;-)
User avatar
beowuuf
Archmastiff
Posts: 20687
Joined: Sat Sep 16, 2000 2:00 pm
Location: Basingstoke, UK

Re: Random numbers and if..then..else conditions

Post by beowuuf »

Basically the cool idea of using the activation probability in conjunction with a counter to generate a random number. Then using the other build in specific functions to read and reset the system after!
Was unable to (permenantly) kill off ian_scho (Haynuus), Ameena, oh_brother (Westian), money (Falkor), raixel (Petal) and Lord_Bones (Aurek) in the DM D&D game Time's Champions!

CONGRATULATIONS TO THOSE WHO MADE THE GAME WHAT IT WAS - GREAT!
User avatar
Lord_BoNes
Jack of all trades
Posts: 1064
Joined: Mon Dec 01, 2008 12:36 pm
Location: Ararat, Australia.

Re: Random numbers and if..then..else conditions

Post by Lord_BoNes »

It works, and quite well too. It's just a bit of mental logic mapping. Think of the tree above, that's a basic representation of what 1 level (64x64) of my dungeon looks like.
In another topic, I touched on my making a random weather system. It uses a similar technique, just with alot more complexity. The counter I use just keeps its value in between a given bracket (EG: 0-15), adding or subtracting at random, using another counter to detect value changes.... Just use 2 relays, one that does: if "counter2"s value less than "counter1", add +1 to "counter2"... and one that does: if "counter2" greater than. Than you can "trap" the value of counter to any given number or variable.
It's actually quite amazing just what you can squeeze out of such a simple process. You just need the time, patience, and logic mapping ability.

Something that helped me with keeping track of relay chains (when used on a single tile) was a clone of a relay with a plain black icon and a blank description (or a bunch of "-" or "*"). I called it my "seperator" and on one tile I might have, for EG:
RELAY1 - triggers RELAY2 then RELAY3 then RELAY4
<SEPERATOR>
RELAY2 - triggers ACTION1
ACTION1
<SEPERATOR>
RELAY3 - triggers ACTION2
ACTION2
<SEPERATOR>
RELAY4 - if condition not met, trigger RELAY1

Another little trick is to use a MISC class item for a timer, clone a FUL_BOMB, give it a lifetime of 1... in the "Expire" convert tab, make its "New Object" itself, and then make your action an OBJECT_ACTIVATE linking to a relay clone's type. You can put one on a given dungeon level to effect ONLY that level... how do you think I update my weather?

One day, I'm gonna write down all my little tricks, I reckon I could make a book :P
 
Image

1 death is a tragedy,
10,000,000 deaths is a statistic.
- Joseph Stalin

Check out my Return to Chaos dungeon launcher
And my Dungeon Master Clone
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Random numbers and if..then..else conditions

Post by Gambit37 »

You need to write that book -- with specific, accurate, repeatable steps and diagrams from the editor showing exactly what to do :-)

Unfortunately I still can't follow some of what you've described. There's too much ambiguity: "this relay", "a relay clone's type" (What relay? this one? that one? Where does it go? How is it linked? What activates it? What does it activate?).

I learn by doing, but I can only "do" if I have clear instructions to follow. Forum language doesn't really help with that since we all just try and get stuff out as quickly as possible without necessarily making it as clear as possible. I'm simply too dumb about this stuff to adequately follow some of what you've written, so anything you can do to make it clearer would be much appreciated. :-)
User avatar
Lord_BoNes
Jack of all trades
Posts: 1064
Joined: Mon Dec 01, 2008 12:36 pm
Location: Ararat, Australia.

Re: Random numbers and if..then..else conditions

Post by Lord_BoNes »

I'll just do an example dungeon for ya. It seems far easier than trying to use words to explain the "simplistic complexity" of dungeon-designing... :P
PM me your e-mail address and I'll send it to ya.... unless Beo wants it (to attach it here).
I'll wait for a response from either of you.

EDIT: I've done that example, I just need a place to send it.
In me doing the example I've actually found that the probability percentage should actually be higher than I expected (50%). For each of the times that it tries to add 1 to the counter, it either is going to add 1 or it's not, so it's a 50/50 chance either way. It now produces the expected results: a random number from 1-5.
 
Image

1 death is a tragedy,
10,000,000 deaths is a statistic.
- Joseph Stalin

Check out my Return to Chaos dungeon launcher
And my Dungeon Master Clone
User avatar
beowuuf
Archmastiff
Posts: 20687
Joined: Sat Sep 16, 2000 2:00 pm
Location: Basingstoke, UK

Re: Random numbers and if..then..else conditions

Post by beowuuf »

E-mail it to Gambit, he can put it on the DM.com webspace anyway!
Was unable to (permenantly) kill off ian_scho (Haynuus), Ameena, oh_brother (Westian), money (Falkor), raixel (Petal) and Lord_Bones (Aurek) in the DM D&D game Time's Champions!

CONGRATULATIONS TO THOSE WHO MADE THE GAME WHAT IT WAS - GREAT!
User avatar
Soaponarope
Artisan
Posts: 190
Joined: Wed Sep 16, 2009 4:18 pm

Re: Random numbers and if..then..else conditions

Post by Soaponarope »

I have done relay trains just like this for my randomization and they do work nicely.

It still doesn't make the chances equal though. Using this method,(let's say from 0-3 random chance), there is a much greater chance you will end up with 1 or 2. There is only a 12.5% chance of activating all or none of the triggers.
Last edited by Soaponarope on Sat Oct 30, 2010 11:51 pm, edited 1 time in total.
User avatar
beowuuf
Archmastiff
Posts: 20687
Joined: Sat Sep 16, 2000 2:00 pm
Location: Basingstoke, UK

Re: Random numbers and if..then..else conditions

Post by beowuuf »

Sounds like you've given them all a 50% chance of firing in the sequence. The first should have 25%, the second 33%, and the third 50% in the sequence if you want a 0 - 3 distributed equally.
User avatar
Soaponarope
Artisan
Posts: 190
Joined: Wed Sep 16, 2009 4:18 pm

Re: Random numbers and if..then..else conditions

Post by Soaponarope »

True, should have thought of that, though I didn't really need equal chances for what I was doing so I will stick with what I already made.
Also those numbers work for making the 0 an equal chance, but make it far more unlikely to get a 3.

Having to use a seperate relay for each chance which then leads to 4+ more, plus the relays to clear counters, all for a single action, really gets crazy when you have several such actions. :shock: Ah well, it works.
Post Reply