MoveObject(player,blah) driving me crazy

Hello all,
new to quest (some experience in programming).
I'm knee deep in creating a game and loving it but this has got me stumped. Using build 5.7.6606.27193.

My intention is to start game with player in 'startroom' and run some initial code to set the game up from the 'Before entering the room for first time' script. This script will then move the player to 'mainroom_centre'

This room is a central room with one room at each compass point around it (n;s;e;w;ne;nw;se;sw) to imitate a larger room that can be navigated.

The idea is to have the rooms initially dark and irrespective of the direction the player chooses, he will be moved to a random room. ie: if he starts in 'mainroom_centre' and types n (for north) he may actually move to any one of the 9 available rooms.

I've set this up with a randroom function called from the 'After leaving room' script on each room.
I have a msg(this.name) on the 'Before entering room' script on each room and a msg(randno) each time the function is called.

But it's going haywire. I've stripped the code right back and re-created in a brand new aslx to test the functionality and its doing the same thing as in the output below
What I'm expecting is in output example one.

Is there something glaringly obvious that I'm doing wrong or can you suggest a better way to do this?
Or is it a bug?
Any help really appreciated.

P.S. I've also noticed that calling the intial MoveObject from 'startroom' to 'mainroom_centre' from the 'startroom' 'Before entering room for the first time' script results in the msg(this.name) to be called twice on mainroom_centre. If I move the MoveObject to the 'startroom' 'Before entering room' script then msg(this.name) on the target room is only called once. Is there a reason for this that you can explain to me?

full aslx on https://gist.github.com/questpacketloss/c6102065c65a4275881edc9b93544ea1

========================================
output example - iteration one
========================================
mainroom_centre
mainroom_centre

n
RandomRoomNumber:4
mainroom_e

========================================
output example - iteration two
========================================
mainroom_centre
mainroom_centre

n
RandomRoomNumber:4
RandomRoomNumber:5
RandomRoomNumber:7
RandomRoomNumber:2
RandomRoomNumber:7
RandomRoomNumber:3
RandomRoomNumber:6
RandomRoomNumber:7
RandomRoomNumber:7
mainroom_se
mainroom_se
mainroom_se
mainroom_se
mainroom_se
mainroom_se
mainroom_se
mainroom_se
mainroom_se

========================================
output example - iteration three
========================================
mainroom_centre
mainroom_centre

n
RandomRoomNumber:5
RandomRoomNumber:6
RandomRoomNumber:4
RandomRoomNumber:4
mainroom_w
mainroom_w
mainroom_w
mainroom_w

===========================
randroom function
===========================
'''
randno = GetRandomInt(1,9)
msg ("RandomRoomNumber:"+randno)
switch (randno) {
case (1) {
MoveObject (player, mainroom_n)
}
case (2) {
MoveObject (player, mainroom_s)
}
case (3) {
MoveObject (player, mainroom_e)
}
case (4) {
MoveObject (player, mainroom_w)
}
case (5) {
MoveObject (player, mainroom_ne)
}
case (6) {
MoveObject (player, mainroom_nw)
}
case (7) {
MoveObject (player, mainroom_se)
}
case (8) {
MoveObject (player, mainroom_sw)
}
case (9) {
MoveObject (player, mainroom_centre)
}
}
'''

======================
full aslx below
======================

'''

'''

Every time you use MoveObject on the player, it calls the exit script for the room they're currently in. Which does the same thing again, and again, until the random generator picks the same room twice in a row.

I'd suggest giving the player a flag to mark that they're currently being moved randomly, so it doesn't call itself.

My version of the randroom function would look like:

if (not GetBoolean (player, "randroom")) {
  player.randroom = true
  game.showdescriptiononenter = false

  // You could use your switch/case block here
  //   I just used a simpler piece of code because it's quicker to type
  room = GetObject("mainroom_" + PickOneString(Split("nw;n;ne;w;e;sw;se;s;centre")))
  MoveObject (player, room)

  game.showdescriptiononenter = true
  player.randroom = false
}

(I also set game.showdescriptiononenter to false, so that it doesn't show the room description twice because of the player being moved twice)


An alternative approach is to move the script from the room object - depending on when it needs to run. If it just runs once at he start of the game, the game.start script. A script on the exit to the room is another possibility (use a "firsttime" script command to have it run just once).


Thank you both for your replies - very much appreciated.
I found moving the the script to the exit object rather than the rooms 'After Leaving' option gave the desired effect without looping and is a cleaner way of achieving what i wanted
But I used your better method of PickOneString for the function mrangel

I just found by accident on a related search the game.pov.lastcommand and lasterror which is something I wanted to incorporate for a number of ideas but couldn't find how to do it till now and didn't know what to search for on the site.
In fact it was in one of your posts that I found this mrangel :-)

I couldn't see a reference to it in the debug browser or the docs (unless its there and i missed it). Is there a list of other such useful references or is there something that I can use in the offline editor that would show ALL available object references/attributes (something like list pov attributes)?

Thanks again


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

Support

Forums