Moving Objects Randomly into a Room and Displaying them

Hi, new to this, so thanks in advance for your help ....

I have worked through the tutorial and am now developing a simple game from a plan I have sketched out.

I have created a room for the game interface and wish to randomly bring objects into the room and display them to the game player in the room. From the interface room then on user input either send the object to another room or return the object to the room.

I have created the Interface room, a 2nd hidden room with objects in it (like the tutorial - bee into the room) and a 3rd destination room.

So far I have been able to bring an object into the room, but need some help with:

a) randomly selecting the object to bring in from all the objects in the hidden room
b) displaying the object once in the room
c) best strategy to use for sending the object from game interface room to another room based on user input


Io

a) What you are looking for is GetRandomInt and Switch. GetRandomInt does exactly what it sounds like, it gets a random integer from a minimum to a maximum, inclusive. In code, it looks like this:

GetRandomInt(1,6)

It's not a block of code. It's something you put INTO the blocks of code.

Switch, in comparison, IS a block of code. Basically you tell it "Depending on what THIS is, do this, this, or this." Think of it like if-then-else, but only for lots of very simple things. So you can do something like:

switch (GetRandomInt(1,6)){
case(1){
move WhateverObject1 to WhateverRoom}
case(2){
move WhateverObject2 to WhateverRoom}
etc}

b) I don't fully understand what you mean by this. You mean add text to the room saying the object's arrived? Just use the Print block of code after you move the object.
c) What you want for THIS is Menu. Menus are probably the single most useful block of code in all of quest. The way it works is it takes a list of strings, and gives the player a choice from each option. Then it does stuff depending on what was chosen. Basic format is, and pardon my psuedocode:

NewStringListForTestingMenu = new string list //Creates a new, empty string list out of the Set Variable Or Attribute block of code. Call it what you want.
Add "Yes" to NewStringListForTestingMenu //Adds the words Yes to an option in the list.
Add "No" to NewStringListForTestingMenu // Ditto for the words No
Show menu with dialogue ("Tell the player to pick Yes or No") taking options from NewStringListForTestingMenu and Do/DoNot allow the player to enter whatever. Then, after they enter something{
Do Stuff}

The big thing to note is that when you enter stuff into a new menu, it creates a variable called 'result' to store it. So after the menu gets input, you can do Switch(result){case 1, case 2 etc} to do different stuff.

Hope this helps!


a) randomly selecting the object to bring in from all the objects in the hidden room

available_objects = GetDirectChildren (hidden room) - gets a list of the available objects
and then
object_to_move = PickOneObject (available_objects) - picks one at random from the list

b) displaying the object once in the room

MoveObjectHere (object_to_move) - move the chosen object into the room
The object will appear in the "places and objects" sidebar, but the player might not notice this, so…
``msg ("A wild " + GetDisplayName (object_to_move) + " appears!")` - displays a message to tell the player an object has appeared.

c) best strategy to use for sending the object from game interface room to another room based on user input

Depending on what you're doing, I'd suggest making a command that sends the object away, and put it in the object's displayverbs. That way, the player can click on the object if they want to send it.

Alternatively, you could use the Ask or ShowMenu functions to ask the player what they want to do with the object when it appears.
The choice between these methods is based on how you want it to look on the player's screen, so that's very much up to you. Once you know what you want the game to do, I'm sure there's plenty of people who can tell you how to do that.


So that the game does not have stuff appearing and disappearing in a room depending on when the player visits, you could run a start script that pre-loads each room with the random stuff, then it only moves when the player moves it.


Io

@DarkLizerd I'm not sure what you mean? It sounds like he/she just wants a way to do something like "Press button for random snack" and you get either "Chips", "Cookies", etc tossed into the room.


@DarkLizerd @lo yes looking for randomly bringing in objects one by one and having the player decide whether he/she wants them or not


So... like a random vending machine...
Push button, and chips appear...


or nuts


Thanks everyone....

Tried this:

A)
available_objects = GetDirectChildren (hidden_room)
object_to_move = PickOneObject (available_objects)
MoveObjectHere (object_to_move)
msg ("Wow " + GetDisplayName (object_to_move) + " appears!")

[brings an object in, but not random, just seems to be the first object from the hidden_room]

B)
MoveObjectHere (object_to_move)
msg ("Wow " + GetDisplayName (object_to_move) + " appears!")

[any ideas on how to display the objects (picture) as they enter the room?]


Io

Have you tried my solution? You also still have not explained what, exactly, you mean by 'display the objects'.


[brings an object in, but not random, just seems to be the first object from the hidden_room]

No, that should be one object chosen randomly from all those in the hidden room.
Could be a coincidence that it's picking the same one.

[any ideas on how to display the objects as they enter the room?]

Well the code you just showed displays the name of the object that appeared.
Do you mean you want to automatically look at the object? Show a picture of it? Something else?
It should also appear in the sidebar, if you have it enabled and the object isn't invisible or scenery.

You already have code that displays the object. If you want to display it in a different way, you need to explain what you want.


@mrangel - yes automatically look at it


Io

@NigelMartin then in that case, in the code after it comes into the room, you can just put a Print block with the same content as that object's Look At block.


So you want something like:
do (lookat, "script", QuickParams ("object", object_to_move))
after moving it into the room?


@lo @mrangel thanks for your help

I managed to get the random object into the room and displayed it picture with user option make a decision to send it to one room or another room.

available_objects = GetDirectChildren (hidden_room)
object_to_move = PickOneObject (available_objects)
MoveObjectHere (object_to_move)
msg ("Wow " + GetDisplayName (object_to_move) + " appears!")
do (lookat, "script", QuickParams ("object", object_to_move))

I used verbs in the objects to let the user select where to send the (object_to_move)

Next step is to clear the screen in the interface room after the object is moved and bring in another random object from the hidden room (repeat until all objects are removed from th hidden room)


I think in that case you probably want to put that code in a function.
Then you can just call the function when the user enters the room, and then call it again after the user has sent it somewhere.

Your function would probably look something like:

available_objects = GetDirectChildren (hidden_room)
if (ListCount (available_objects) > 0) {
  object_to_move = PickOneObject (available_objects)
  MoveObjectHere (object_to_move)
  msg ("Wow " + GetDisplayName (object_to_move) + " appears!")
  do (lookat, "script", QuickParams ("object", object_to_move))
}
else {
  // Script goes here
  // for what will happen when the hidden room is empty
}

Io

Agreed with Mr. Angel. Any time you have code you want to use more than once, there's no harm making a Function.


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

Support

Forums