Hide objects in rooms randomly?

ty13r
:?: What's the easiest method for hiding an object randomly within one room of a set of rooms on game load, so every time the user plays the object they're looking for isn't in the same location?

Pertex

roomarray= split("room1;room2;room3", ";")
MoveObject(yourobject, GetObject(StringListItem(roomarray, GetRandomInt (0, 2))))


In the first line add all rooms where the object could be placed. Then change the maximum range of the GetRandomInt function. The maximum is number of rooms -1. So if you have 5 rooms the GetRandomInt function looks like "GetRandomInt (0, 4)"

ty13r
Pertex wrote:

roomarray= split("room1;room2;room3", ";")
MoveObject(yourobject, GetObject(StringListItem(roomarray, GetRandomInt (0, 2))))


In the first line add all rooms where the object could be placed. Then change the maximum range of the GetRandomInt function. The maximum is number of rooms -1. So if you have 5 rooms the GetRandomInt function looks like "GetRandomInt (0, 4)"


Simple and straightforward explanation. Thank you!

HegemonKhan
slight improvement that Pertex forgot to do (or he was just keeping it more simple for you), so you don't have to manage changing list quantity of items:

(learning and understanding List/Dictionary Attributes is quite advanced for those who don't know how to code already, this isn't easy stuff to grasp or to explain about it too)

roomarray= split("room1;room2;room3", ";")
MoveObject(yourobject, GetObject(StringListItem(roomarray, GetRandomInt (0, ListCount (roomarray) - 1))))


---------

quest has 4 built-in Randomization Functions:

http://docs.textadventures.co.uk/quest/ ... omint.html
http://docs.textadventures.co.uk/quest/ ... ouble.html
http://docs.textadventures.co.uk/quest/ ... eroll.html
http://docs.textadventures.co.uk/quest/ ... hance.html
^^^^^^^^^^^
http://docs.textadventures.co.uk/quest/ ... tions.html (the above 4 links are found here)

------------

1. GetRandomInt (<min_value>, <max_value>)
2. GetRandomDouble () // it automatically chooses between 0.0 and 1.0

3. DiceRoll (<number of die>d<number of sides on die>)

4. RandomChance (<0-100>) // this is the percent chance of something being (returns) true

---------

List and Dictionary Attribute Usage:

http://docs.textadventures.co.uk/quest/ ... lists.html
http://docs.textadventures.co.uk/quest/ ... aries.html

--------

a good combination is to use 'GetRandomInt()' to select an item from a group (Using Lists/Dictionaries), and then use the 'RandomChance()' for the percent chance of actually doing something/whatever or getting_it/whatever with that item or not.

for conceptual example:

treasure chest / drop :
-> 1. candy
-> 2. chocolate
-> 3. sugar
-> 4. honey

'GetRandomInt()' will select one of these items // ie chocolate is chosen

and then 'RandomChance()' will determine whether you actually get that item (if its actually given to you/put in your inventory), or not (failure) // ie will you now actually receive the selected chocolate item or not

ty13r
HegemonKhan wrote:slight improvement that Pertex forgot to do (or he was just keeping it more simple for you), so you don't have to manage changing list quantity of items:

(learning and understanding List/Dictionary Attributes is quite advanced for those who don't know how to code already, this isn't easy stuff to grasp or to explain about it too)

roomarray= split("room1;room2;room3", ";")
MoveObject(yourobject, GetObject(StringListItem(roomarray, GetRandomInt (0, ListCount (roomarray) - 1))))


---------

quest has 4 built-in Randomization Functions:

http://docs.textadventures.co.uk/quest/ ... omint.html
http://docs.textadventures.co.uk/quest/ ... ouble.html
http://docs.textadventures.co.uk/quest/ ... eroll.html
http://docs.textadventures.co.uk/quest/ ... hance.html
^^^^^^^^^^^
http://docs.textadventures.co.uk/quest/ ... tions.html (the above 4 links are found here)

------------

1. GetRandomInt (<min_value>, <max_value>)
2. GetRandomDouble () // it automatically chooses between 0.0 and 1.0

3. DiceRoll (<number of die>d<number of sides on die>)

4. RandomChance (<0-100>) // this is the percent chance of something being (returns) true

---------

List and Dictionary Attribute Usage:

http://docs.textadventures.co.uk/quest/ ... lists.html
http://docs.textadventures.co.uk/quest/ ... aries.html

--------

a good combination is to use 'GetRandomInt()' to select an item from a group (Using Lists/Dictionaries), and then use the 'RandomChance()' for the percent chance of actually doing something/whatever or getting_it/whatever with that item or not.

for conceptual example:

treasure chest / drop :
-> 1. candy
-> 2. chocolate
-> 3. sugar
-> 4. honey

'GetRandomInt()' will select one of these items // ie chocolate is chosen

and then 'RandomChance()' will determine whether you actually get that item (if its actually given to you/put in your inventory), or not (failure) // ie will you now actually receive the selected chocolate item or not



Thank you so much for the awesome more advanced answer!

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

Support

Forums