Exiting a room puts you in a random location - How?

Carrot
18 May 2009, 21:42
Firstly, sorry if this has been posted or asked before. I have done a quick search and couldn't find anything relevant.

I currently only have QDK Lite, but am tempted to U/G.

I would like to assign a random result (from a predefined list of "rooms"). Ideally this is to be used with compass points rather than "out".

I am presuming I need to use the random command somehow, and attach a script to the exit, but how to write that script I am unsure.

For arguments sake, I have 3 rooms. Room 1 is exitable by all 8 compass points, but the result of using any of the exits will be a random choice of one of the other two rooms.

Many thanks.

Overcat
18 May 2009, 23:34
The following will work under version 4.10:

define game <Test Game>

asl-version <410>
background <black>
foreground <white>

start <StartRoom>

end define

define options

debug on
panes off

end define

define room <StartRoom>

alias <Start Room>
look <A most boring location.>

north {
goto <$GetRandomLocation$> }
south {
goto <$GetRandomLocation$> }
west {
goto <$GetRandomLocation$> }
east {
goto <$GetRandomLocation$> }
northwest {
goto <$GetRandomLocation$> }
southwest {
goto <$GetRandomLocation$> }
southeast {
goto <$GetRandomLocation$> }
northeast {
goto <$GetRandomLocation$> }

end define

define room <AnotherRoom>

alias <Another Room>
look <Another boring location.>

south <StartRoom>

end define

define room <YetAnotherRoom>

alias <Yet Another Room>
look <Yet another boring location.>

south <StartRoom>

end define

define function <GetRandomLocation>

set numeric <num; $rand(1; 2)$>

select case <%num%> {
case <1> set string <Location; AnotherRoom>
case <2> set string <Location; YetAnotherRoom>
}

return <#Location#>

end define


If you have any questions about the ASL above, ask away.

For others (including Alex) who may have attempted this, for some reason this statement would not work:

north <$GetRandomLocation$>


I would get these errors:

"Error 9 - Subscript out of range

in RoomExits.AddExitFromTag"

and

"Run-time error '91':

Object variable or With block variable not set"

Carrot
18 May 2009, 23:58
Thank you.

I saved that and then loaded it. But I am running 4.0.5 (went to update, it says mine is the latest version, it is lite not pro if that makes a diff?)

Anyhow, it only seems to send me to "Yet Another boring Location", never "Another Boring Location" (Could be the version difference?)

Also, bar editing the ASL directly in say notepad, how do I edit $GetRandomLocation$ ?

Overcat
19 May 2009, 10:13

I saved that and then loaded it. But I am running 4.0.5 (went to update, it says mine is the latest version, it is lite not pro if that makes a diff?)



My hunch is it won't.

Anyhow, it only seems to send me to "Yet Another boring Location", never "Another Boring Location" (Could be the version difference?)



Hmm. Are you sure? I thought that too, when I first ran it - but it was just that the same room was randomly selected several times in a row. Works for me. How many times do you check it? You can type 'south' or 's' repeatedly, since both "Another Boring Location" and "Yet Another Boring Location" exit southward to the start room.

Also, bar editing the ASL directly in say notepad, how do I edit $GetRandomLocation$ ?



I'm using 4.1 Beta, so I don't know if the following will be the same for you:

In the tree at the left in the QDK window, navigate to Game -> Functions. 'GetRandomLocation' should be listed on the right after you click 'Functions'. Click 'GetRandomLocation', and then click the 'Edit' button. A window will pop up that allows you to edit the script statement by statement.

If that doesn't work for you, then perhaps 4.05 is just layed out differently. (I don't use the QDK, so I can't recall what any of the differences are between the new and old versions.) If it is the case that it's just layed out differently, try to find somewhere in the interface that allows you to edit 'functions'. Maybe the tutorial will have something on that.

Carrot
19 May 2009, 19:20
Overcat wrote:

Anyhow, it only seems to send me to "Yet Another boring Location", never "Another Boring Location" (Could be the version difference?)



Hmm. Are you sure? I thought that too, when I first ran it - but it was just that the same room was randomly selected several times in a row. Works for me. How many times do you check it? You can type 'south' or 's' repeatedly, since both "Another Boring Location" and "Yet Another Boring Location" exit southward to the start room.


Yup. I tried it about 10 times last night and either I wasn't reading it correctly, or it was throwing a strop. Just tried it again (from the save file - not a new import) and it worked fine.

Overcat wrote:

Also, bar editing the ASL directly in say notepad, how do I edit $GetRandomLocation$ ?



I'm using 4.1 Beta, so I don't know if the following will be the same for you:

In the tree at the left in the QDK window, navigate to Game -> Functions. 'GetRandomLocation' should be listed on the right after you click 'Functions'. Click 'GetRandomLocation', and then click the 'Edit' button. A window will pop up that allows you to edit the script statement by statement.

If that doesn't work for you, then perhaps 4.05 is just layed out differently. (I don't use the QDK, so I can't recall what any of the differences are between the new and old versions.) If it is the case that it's just layed out differently, try to find somewhere in the interface that allows you to edit 'functions'. Maybe the tutorial will have something on that.



I'll have a read through the manual. In the left Pane, I have

[list]
[*]QDK[/*:m]
[*]Game[list]
[*]Verbs[/*:m]
[*]Commands[/*:m][/list:u][/*:m]
[*]Rooms[list]
[*]StartRoom[/*:m]
[*]AnotherRoom[/*:m]
[*]YetAnotherRoom[/*:m][/list:u][/*:m][/list:u]

Thanks for your help.

[edit]

To edit function in 4.0.5, its in the Tools menu. :)

[/edit]

Alex
20 May 2009, 19:13


For others (including Alex) who may have attempted this, for some reason this statement would not work:

north <$GetRandomLocation$>



This seems to work fine for me in the latest build, possibly it was fixed as a side-effect of me fixing something else. I'll update the beta build soon.

Carrot
20 May 2009, 19:59
Alex wrote:


For others (including Alex) who may have attempted this, for some reason this statement would not work:

north <$GetRandomLocation$>



This seems to work fine for me in the latest build, possibly it was fixed as a side-effect of me fixing something else. I'll update the beta build soon.



Do you mean in place of

...
north {
goto <$GetRandomLocation$> }
...

Overcat
20 May 2009, 20:30


Do you mean in place of

...
north {
goto <$GetRandomLocation$> }
...



Yes. That would have been simpler, and was what I'd originally tried.

Carrot
20 May 2009, 21:13
I changed

north { 
goto <$GetRandomLocation$> }
south ...

to
north <$GetRandomLocation$> 
south ...


in the ASL.

When i loaded it back into 4.0.5 (I have 4.1 beta pro now as well ;)) and tried to run it, I got a "You cant go in that direction" message. I opened the QDK, and looked at the room. In the exits, in place of [script] was $GetRandomLocation$

Carrot
20 May 2009, 21:53
Changing it to

north { 
<$GetRandomLocation$> }
south ...


Makes the room have its exits, but when you enter a direction, nothing happens

Carrot
20 May 2009, 22:05
OK, new to this code, so possibly a bug? dunno.

I get different results just by using a newline (which I thought, from the layout of the code, wouldn't be important).

In 4.0.5

north { 
goto <$GetRandomLocation$> }

works


north 
<$GetRandomLocation$>

doesn't give north in the list of exits, and entering N gets "you can't go there"


and

north { goto <$GetRandomLocation$> }

Leaves the location in the available list - but does nothing when you enter the direction command.


in 4.1 beta the only difference is that using the N on option 2 gives a selection of NW or NE instead of "you can't go there"

Overcat
21 May 2009, 01:33

Changing it to


north {
<$GetRandomLocation$> }
south ...


Makes the room have its exits, but when you enter a direction, nothing happens



That's because as soon as you apply curly brances after the exit tag (in this case the 'north' exit tag), Quest runs a script. That as opposed to running its built-in functionality for the exit tag when you merely specify a tag value. When you only specify a tag value, as in...

north <someroom>


...Quest automatically sends the player to the room indicated by the tag value (in this case, a room named 'someroom'). In your above example you run a script that doesn't do anything. Well, something does happen - a script runs. But the script doesn't output anything for the player, so you don't see anything. Try this:

north { 
<$GetRandomLocation$>
msg <North it is!> }


...and you should see what I mean. If you watch the ASL Log Window, you should also see this:

ERROR: Unrecognized keyword. Line reads: '<$GetRandomLocation$>'

north { goto <$GetRandomLocation$> }


Leaves the location in the available list - but does nothing when you enter the direction command.



Yes, I experienced that also, as I attempted to put the script all on one line. That won't work, but I think it should (white space shouldn't matter). Incidentally, this is the same for object actions:

define object <SomeObject>

...
action <SomeAction> { msg <Action fired.> }
...

end define


That won't work, but this will:

define object <SomeObject>

...
action <SomeAction> {
msg <Action fired.> }
...

end define


This touchiness on white space does constitute a bug, I think, since the help file (if I remember correctly) indicates that white space doesn't matter.

Carrot
21 May 2009, 19:14
Alex wrote:


For others (including Alex) who may have attempted this, for some reason this statement would not work:

north <$GetRandomLocation$>



This seems to work fine for me in the latest build, possibly it was fixed as a side-effect of me fixing something else. I'll update the beta build soon.



So for the time being I should stick with

north {
goto <$GetRandomLocation$> }