Not so random, random sound events

I'd like to have a clap of thunder go off randomly, but also have them follow some rules.

  • Only go off once player reaches a certain point in the game
  • Picked at random from three or four different 'claps' to avoid sounding repetitive
  • Control the frequency at which they happen (don't want claps going off within seconds of each other)
  • Stop happening after a given length of time.

I'm not asking for this to be done for me, but I've never done anything with random events and wouldn't really know where to start.


Well you have your rules, now you just have to translate them into code logic

1: can be done with a basic flag or script at the specified point in the game that activates the script or object that controls the thunder.

2: use built in random number selection and have each number (or range of numbers if you want to adjust the probability of each) assigned to a specific sound clip.

3:again random number generation, I'd probably make it a countdown and set the minimum value to whatever you want the shortest possible time frame to be.

4:timer script started at the same time thunder is activated, have it turn off whatever the initial script turned on.


Thanks, TinFoil. I suppose I need to have a play around as none of that means much to me as of now.

I'm sure I could suss out the flag stuff, but random number selection, etc, is all alien to me.


Well this is probably a good starting point http://docs.textadventures.co.uk/quest/functions/getrandomint.html as that's the function I'd probably end up using.

For #2 its as easy as doing a random 1-4 or however many soundclips you have, then play the clip number it picks.

For the #3 what I would do is create a timer for when the actual sound plays, and when it goes off play your sound effect and set the timer duration to a random number again, using the getrandomint to create a minimum and maximum time till the next sound goes off.

Using random selection is the same as giving the player a set of choices, however you're giving the choice to the script instead and using a random number function to pick one.


GetRandomInt (integer min, integer max)

This is from the link you provided, but I'm afraid as far as being instructional goes, it's about as much use as a chocolate fireguard. I know enough to know that just putting the above script in a room isn't going to randomly play the sound of thunder for me, but at the same time I have no idea how to convert that into what I would need. I don't even know what an integer is.

As always I will look for easier ways out, and I think just adding the different sound clips manually, at different points will be far less of a headache.


Integer is just a whole number ie: 1 is an integer 1.34 is not an integer. It just means a number that isn't a decimal or fraction.

You'd probably be building it into a timer script, but if you can get something more basic that does what you want go for it.


Thanks for your help. By the way that last comment about the link wasn't directed at you, just the Quest tutorials in general.


the 'GetRandomInt' function does this:

you input the range of numbers to select from, for example '0 to 100' (101 total numbers for it to choose from: 1 through 100 and 0: 100+1=101): GetRandomInt (0, 100), and the Function uses some algorithm to select a number within that range you've given it (giving it the illusion of randomness --- as there's no actual thing as randomness, as "everything is a formula"), and it then returns that selected number.

but, this Function by itself is usually worthless. You need to actually do something with that returned-selected number...

which gets us to (usually using) Lists, as the items in a list have asssociated number values (their 'index numbers', starting from the left if in coding or from the GUI/Editor the first item you add to a list, as index number 0 item, index number 1 item, index number 2 item, etc etc etc). Now, that randomly selected number from 'GetRandomInt', is doing something, via using a list to get the item associated with that same number value via that list item's index number. To get and return an item from a list using the index number, you use the: generalized/universal 'ListItem', or the specific Attribute type ones: 'StringListItem' or 'ObjectListItem', Functions

for example:

<game name="example_game">
  <attr name="color_stringlist_attribute" type="simplestringlist">red;blue;yellow</attr> // Red (index number: 0), blue (index number: 1), and yellow (index number:2)
  <attr name="start" type="script">
    randomly_selected_color_string_variable = StringListItem (game.color_stringlist_attribute, GetRandomInt (0,2))
    msg (randomly_selected_color_string_variable)
  </attr>
</game>

you only have to use '0' as the min range value for your 'GetRandomInt' Function's Parameter (input), due to List Attributes starting at index number 0. Though, if you don't like using zero, you can always do this:

'GetRandomInt (1,100) - 1' is the same as doing 'GetRandomInt (0,99)' // you CAN do this for getting a List's item
~or, the opposite/reverse~
'GetRandomInt (0,99) + 1' is the same as doing 'GetRandomInt (1,100)' // but you can't do/use this for getting a List's item !!!!!


also, for your max range value, when working with using the 'GetRandomInt' with Lists, is to use the 'ListCount(NAME_OF_OBJECT.NAME_OF_LIST_ATTRIBUTE) -1', as your various lists will have differing quantity of items as well as individual lists having their quantity of items being changed (you add/remove item to/from the list during game play). Using the 'ListCount(LIST) -1' will handle this all for you:

randomly_selected_string_variable = StringListItem (NAME_OF_OBJECT.NAME_OF_LIST_ATTRBIUTE, GetRandomInt (0, ListCount (NAME_OF_OBJECT.NAME_OF_LIST_ATTRBIUTE) - 1))

and here's a more detailed guide/explanation on using Lists/Dictionaries:

http://textadventures.co.uk/forum/samples/topic/5137/list-and-dictionary-extensive-guide-by-hk


as, already been explained by Tin:

an 'integer/int' in math/programming, is a number that is not a decimal number: ..., -3289798323, -5, 0, 3, 28902903, ...

a 'decimal/fractional number (or whatever the fancy name for it, is in math, lol-meh)/double/float/floating-point' in math/programming, is: ..., -353.9999, -1.123, 0.0, 2.93, 2839283902.4, ....

a 'whole number (if I remember right, too lazy to look up)' in math is: positive numbers (this EX-cludes zero): 1, 2, 3, 4, 32392382938293, ...


in programming, working with decimal numbers takes much more work than working with integers (if you can, it's better to not use decimal numbers), due to how computers/programming works...

(two seperate operations: one to find the integer value to the left of the decimal, the other to find the decimal value to the right of the decimal, along with usually having to shift the bits, and replace the decimal into the correct spot to separate the integer values from the decimal/fractional values for the answer/returning/new decimal number to you. Decimals are jsut so much more messy to work with in computers/programming, as computers are dumb, whereas humans can easily and quickly do what is much slower/harder for computers to do, making it easy and quick for our brains to handle decimal numbers, whereas it's harder for the computer to do so, and thus harder for you if you got to do the coding in of it, and also thus due to having to do more work, means that the performance/speed is slower: a computer having to do more work means longer wating time for you than the computer having to do less work. ie "efficiency" handling. General-simple operations, due to our modern computers, generally the increased work/time is unnoticeable, but for critical systems, limited memory/space, and/or complex programs doing trillions of operations, doing more work than needed: inefficiency, can become extremely noticeable... the computer seems to freeze/not do anything... you're waiting on the computer to complete the action for a long long long long time).

And then there's all the programming of the various types of rounding handling... as there's finite resources, a computer/calculator will run out of memory/space in trying to return pi, so there's a rounding cut-off/termination required, as well as people wanting the various types of rounding handling (round up/ceiling, round down/flooring, truncation, etc, etc).

Very very very messy... (when you understand a bit of how messy decimal/fraction programming is... you really appreciate calculators, and those who programmed in this mess for you into the calculators, lol)


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums