Different descriptions when entering a room from different directions

Forgewright
If I want different view points(room descriptions)coming from different exits into the same room how can I determine or identify which exit was just used to enter the room? The before and after entering room scripts don't do this. I need a code line to identify the last exit used.....Right.
Any examples would be mucho appreciated.

jaynabonne
I had a similar desire in my game (an old one that I never finished). The solution involved two parts:

1) Override the core exit types and add a field to indicate the direction.
2) Override the "go" command to store the last exit the player traversed into the pov object.

With those two pieces, you can then query "game.pov.lastExit.direction" to find out what the last direction was.

Here is the code to add to your game:

  <command name="go" pattern="[go]" unresolved="[UnresolvedLocation]">
if (exit.visible) {
if (exit.locked) {
msg (exit.lockmessage)
}
else if (exit.runscript) {
if (HasScript(exit, "script")) {
do (exit, "script")
}
}
else if (exit.lookonly) {
msg ("[UnresolvedLocation]")
}
else {
game.pov.parent = exit.to
game.pov.lastExit = exit
}
}
else {
msg ("[UnresolvedLocation]")
}
</command>
<type name="northdirection">
<inherit name="compassdirection" />
<alias>north</alias>
<alt type="simplestringlist">n</alt>
<direction>northdir</direction>
</type>
<type name="northwestdirection">
<inherit name="compassdirection" />
<alias>northwest</alias>
<alt type="simplestringlist">nw</alt>
<direction>northwestdir</direction>
</type>
<type name="westdirection">
<inherit name="compassdirection" />
<alias>west</alias>
<alt type="simplestringlist">w</alt>
<direction>westdir</direction>
</type>
<type name="southwestdirection">
<inherit name="compassdirection" />
<alias>southwest</alias>
<alt type="simplestringlist">sw</alt>
<direction>southwestdir</direction>
</type>
<type name="southdirection">
<inherit name="compassdirection" />
<alias>south</alias>
<alt type="simplestringlist">s</alt>
<direction>southdir</direction>
</type>
<type name="southeastdirection">
<inherit name="compassdirection" />
<alias>southeast</alias>
<alt type="simplestringlist">se</alt>
<direction>southeastdir</direction>
</type>
<type name="eastdirection">
<inherit name="compassdirection" />
<alias>east</alias>
<alt type="simplestringlist">e</alt>
<direction>eastdir</direction>
</type>
<type name="northeastdirection">
<inherit name="compassdirection" />
<alias>northeast</alias>
<alt type="simplestringlist">ne</alt>
<direction>northeastdir</direction>
</type>
<type name="updirection">
<inherit name="updowndirection" />
<alias>up</alias>
<alt type="simplestringlist">u</alt>
<direction>updir</direction>
</type>
<type name="downdirection">
<inherit name="updowndirection" />
<alias>down</alias>
<alt type="simplestringlist">d</alt>
<direction>downdir</direction>
</type>
<type name="indirection">
<inherit name="inoutdirection" />
<alias>in</alias>
<alt type="simplestringlist"></alt>
<direction>indir</direction>
</type>
<type name="outdirection">
<inherit name="inoutdirection" />
<alias>out</alias>
<alt type="simplestringlist">o</alt>
<direction>outdir</direction>
</type>


The direction fields have names like "northdir", "southdir", etc. I decided to go that route rather than using (say) the "alias" field, as those other fields were user-facing and would be changed if the game were ever translated to a non-English language.

Let me know if you need anything clarified. I believe if you just drop that in your game somewhere (e.g. before the closing </aslx> element), then it should just work.

As always, be sure to backup your game before doing any major mods like this...

HaganeSteel
You can do this by switches too.

Give your room two switches: Under the "Attributes" tab for your room, next to where it says "Attributes," click "Add." Create two variables and set them to "Boolean." They should both be "False."

Then click the "Room" tab. Next to where it says "Description," set it to "Run Script" instead of "Text."

Click "Add New Script," and scroll down to where it says "If..."

Next to where it says "Expression," type: roomname.north = true. "roomname" is the name of your room, and "north" is the name of one of the boolean attributes you created. Under "Then," select "Add New Script" and then "Print." Now print your room description.

Then go down to "Else If" and do the same thing: roomname.south = true. Under "Then" print your second message.

Doorways are objects. Go to your doorway objects (located in the other rooms), and select: "Run script (instead of moving the player automatically)."

Select "Add New Script," and do three things: First, "move object." Move "player" to "roomname." Then "Add New Script" and "Set variable or attribute." Type: roomname.north in the first box, and "true" in the second. Then "Add New Script" and "Set variable or attribute" again. Type: roomname.south in the first box, and "false" in the second.

For the second door object, do the same thing, but reverse the "true" and "false."

I want to give you screenshots for this, but I actually don't have time right now. I'm sorry. I hope this was clear enough.

jaynabonne
That approach makes sense if you just have a few exits to do. I would hate to have to do that for every exit in a large layout (which is what I had). But it certainly can be a straightforward way to do it if you only have a few that you want to track.

HaganeSteel
Absolutely. I wanted to offer a less programming-intensive solution. I'm only a pretend-programmer, so I have to find the easiest workarounds for problems like these. :lol:

jaynabonne
I hope I didn't sound too dismissive. It's actually a good, creative way to tackle the problem. :)

HaganeSteel
Oh, no, you're fine!

If you think that's tedious, you should see the dizzying amount of code it takes to get a single zombie working in my game. :lol:

I have reinvented the wheel fifteen times now. 8)

Sorry for derailing the thread! I'll shut up now!

HegemonKhan
don't worry, we code-noobs all got the same problem... Jay's a good coder, he understands how things should be coded to work as a great system (higher level or scale of code ~ game-code designing), which also means avoiding all the pitfalls~bugs that occur for us code-noobs due to our noob-coding, with the least amount of code as possible, and such etc advanced coding organizational~structural~design stuff, whereas, we get excited just with getting a functional code directly for the thing we want done or have to do in our game, laughs. As we learn more coding, we slowly get a little better, but Jay, Pixie, Pertex, and etc other people, have a ton of code knowledge ("lightyears" of code beyond us), which we're not even remotely close to having yet.

I was so estatic at finally getting my basic combat code to work (using Pertex' Combat Code as my structure), but then Pertex took only like 5 minutes to both: (1) undersand my code (it took me like 2 days to understand neonayon's game code... AFTER I re-organized it for myself, lol), and (2) then vastly improved upon it (Pertex like cut my code in half ~ I had really bad and unnessary parts of code in my code)... My jaw dropped to the floor and my head hit the table... I wasn't as jubilant afterwards, laughs. I'm still constantly amazed at the good coders here, I'm trying to eventually reach their level... maybe before I die, maybe... laughs.

-------

for us code-noobs, 're-inventing the wheel', is good, as it is us trying to understand coding, whereas the good coders, are like 'why waste your time, when its already done for you?', but for us, it is us learning code, we are exploring code, discovering and understanding more about it by 'trying to reinvent the 'wheel'. Ya, we can just use others code, but in doing so, we as code-noobs, never understand that code, and thus can't implement it and~or nor apply it, for anything else.

it's like with math (not the best example, but meh):

ya, you can remember '5x5=25', but if you don't understand what multiplication is '5 groups each containing 5 items', then you're not going to be able to do '2x8=16', unless you got that memorized too.

Forgewright
Well said HegemonKhan

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

Support

Forums