Page 1 of 1

Two things I've had trouble implementing

Posted: Fri Jun 03, 2005 7:12 am
by Jon Fry
Hi. I'm a sort of newcomer to Hugo. Last summer I began work on two games (one a short piece for the competition, the other a large cave-crawl) but stopped working on each when I encountered something I couldn't figure out how to implement in the system. Now that I've got a summer coming up I thought I'd have another go at them, so any help would be appreciated:

1) In the first game, the order that a player moves after entering Room X is the solution to a puzzle. So, I'd like to be able to say that if Player Y is in Room X and then moves "N, N, NW" (for example), a certain thing occurs. Otherwise, nothing occurs and the buffer resets when Player Y enters Room X again.

2) The other thing I couldn't implement is described in this message to r.a.i-f from last summer:

http://groups-beta.google.com/group/rec ... 30b272a008

Help with either issue would be appreciated. (The more explicit the answer is in terms of code, the better. :smile: )

Thanks,
Jon

Re: Two things I've had trouble implementing

Posted: Fri Jun 03, 2005 8:49 am
by Ice Cream Jonsey
Jon Fry wrote:1) In the first game, the order that a player moves after entering Room X is the solution to a puzzle. So, I'd like to be able to say that if Player Y is in Room X and then moves "N, N, NW" (for example), a certain thing occurs. Otherwise, nothing occurs and the buffer resets when Player Y enters Room X again.
What about putting together an array and doing something like this:

RoomArray[3] = 0,0,0

Then when entering the first room do something like

RoomArray[1] = 1

(OK, please excuse me... I can't remember if Hugo's first array element is 0 or 1. But set it to the appropriate number for your code.)

When you go to the other rooms from your first one, reset RoomArray[1] = 0. However, when going to the north one check to see if RoomArray[1] = 1 and if it is, set RoomArray[2] = 1.

Then repeat this process for the last room that you get to by going NW. I think this would work so long as you knocked the first array element to 0 whenever the "wrong" path is taken.

I can throw up a little more code on this later if that'll help.


Robb

Re: Two things I've had trouble implementing

Posted: Fri Jun 03, 2005 9:10 am
by Jon Fry
Ice Cream Jonsey wrote:I can throw up a little more code on this later if that'll help.
If it's not a huge amount of work, that would be very much appreciated. :cool:

In either case, thanks for the response -- it gives me some things to read up on. I'm still pretty new to Hugo and haven't done much beyond creating basic rooms and objects.

Jon

Posted: Fri Jun 03, 2005 11:09 am
by Guest
Zero-based.

ICJ has the same solution I would have given, more or less. Track a status as long as the player continues on the right course. You might be able to simplify it, though, but just using one variable. Here's kind of how it would work.

X = 0 !Use to indicate player hasn't started the pattern.

X = 1 !Use to indicate player has entered the first room.

X = 2 !If X was 1 and player enters the second room...
!Otherwise if X is already 2, leave it alone.
!Otherwise set X to 0.

X = 3 !If X was 2 and player enters the third room....
!Otherwise if X is already 3, leave it alone.
!Otherwise set X to 0.

...etc

If you also created an array of all the room objects, it would be even easier. You could simply check to see if the player is in a different room than before, and if so, increment X. If room[x] is the player's current room at that point, they're on the right path. Otherwise, they took a wrong turn, so reset and start over.

You'd also have to keep track of when the player completed the pattern, otherwise you'll be accessing out of bound indices for roomlist.

You'd probably also want to make sure the player hasn't already completed the puzzle -- or else, check to make sure it's okay for the player to *start* the puzzle.
Let's see if I can whip up some code:

Code: Select all

array roomlist[4]
global goodroom=0
global maxrooms = 6
global CanDoPuzzle = true
roomlist[0] = First_room, Second_room, \
Third_room, Fourth_room, Fifth_room, Sixth_room

!Then, in your you{} object for actor room-movement,
!or maybe as a routine you call from each_turn in all
!applicable rooms, you'd do something like this:

if (roomlist[goodroom] != location)  and (CanDoPuzzle) {
    goodroom++
    if (roomlist[goodroom] = location) {
        if (goodroom = 1) {
            !Maybe announce that the puzzle is starting.
        } else {
            if (goodroom = maxrooms) {
                 !Congrats! You've solved it!
                 !Do whatever needs done, here.
                 CanDoPuzzle = false
            }
        }
    } else {
        goodroom = 0
        !The user took a wrong turn! Start over!!!
    }
}

Posted: Fri Jun 03, 2005 11:10 am
by Merk
Woops, I did a Kent. Forgot to log in. :) That last post was from me. Sorry.

If you wanted to base the pattern strictly on the directions taken, and *not* the rooms entered (i.e., if you had a maze with rooms that link back on each other), then you could probably do the same thing by checking for the DoGo action. Have you roomlist be a "dirlist" instead, and just check to see if the last direction the player has gone is the next one in the list.

Posted: Fri Jun 03, 2005 11:24 am
by Merk
As for the second question, that's harder. Using "* string" in a verb expects for the string to be enclosed in quotes. For example:
verb "mode"
* string DoModeParsing
This would support:
mode "intox"
mode "normal"
and so forth. Actually, this comes from Trading Punches. I have a line for non-quoted mode that I handle, *plus* a parsing routine in case the user quotes the string:
verb "mode"
* "normal" DoModeNormal
* "intox" DoModeIntox
* "compass" DoModeCompass
* "translate" DoModeTranslate
* "xyzzy" DoXyzzy
* string DoModeParsing
DoModeParsing looks like this:
routine DoModeParsing
{
if IsEqual(parse$,"normal","Normal","NORMAL") {
DoModeNormal
} elseif IsEqual(parse$,"intox","Intox","INTOX") {
DoModeIntox
} elseif IsEqual(parse$,"compass","Compass","COMPASS") {
DoModeCompass
} elseif IsEqual(parse$,"translate","Translate","TRANSLATE") {
DoModeTranslate
} elseif IsEqual(parse$,"xyzzy","Xyzzy","XYZZY") {
DoXyzzy
} else {
DoMode(99) !Will give the "nothing happens" message.
}
}
The "IsEqual" function is one that I wrote, so that it could compare the first string to several possible choices. It basically just does a series of StringEqual() comparisons against the first parm and each of the additional parms.

This may not help you... but I think the only way to support 150 questions and answers would be to require that the user put their answer in quote marks. Then you could loop through the answers given, and do a comparison of StringEqual() for each possibility.

Posted: Fri Jun 03, 2005 11:41 am
by Guest
Merk wrote:This may not help you... but I think the only way to support 150 questions and answers would be to require that the user put their answer in quote marks. Then you could loop through the answers given, and do a comparison of StringEqual() for each possibility.
Thanks for the piece of code for the first problem -- I'm going to try incorporating it immediately.

As for this question and answer issue, I should say that I don't really mind if the player has to use quotation marks in giving the answer. What I was having difficulty doing was building the database of questions and answers. I imagine there would have to be a unique identifier (question number or something) which I could then access to pull out both the question text to print and also to contain the answer text to compare to the player's input. I'm just not sure how to model that sort of table in Hugo, or how to do such a comparison. Does that make sense?

Thanks again,
Jon

Posted: Fri Jun 03, 2005 12:34 pm
by Merk
Well, the brute-force way would be to use two arrays:

Array questions[150]
Array answers[150]

And then, just start initializing them!

Hugo also has the ability to read and write text files (I think). So, it would *probably* be possible to have your questions and answers in a file that you just open, and loop through. I'd have to check my Hugo manual later to know for sure, but I think it's possible.

Also, in my room-map code snippet, there may be errors (I didn't try compiling it). I know there's a problem in checking for MaxRooms though -- I think you'd need to check for MaxRooms - 1. Not sure. I can post some revised code later.