Universal command for applying a flag when moving between rooms?

XanMag
Okay... sorry in advance.

In my game I intend on having a flag set and unset called 'inside'. Every time the player goes inside (indoors), the flag 'inside' is set. I'm doing this so I can set up different description for my random bats that show up during certain times of the day. Obviously, the description will differ depending on the time of day and whether or not the player is indoors or outdoors. Whenever the bats have arrived when the player is indoors, there is a flag set called 'presentin' so the room description and arrival/departure of the bats has a proper description. Note: 'presentin' doesn't mean that bats are ever indoors. They are always outdoors but the player can hear them 'just beyond the walls.' There is also a 'presentout' flag set when the bats arrive when the player is outdoors. This much is established so far.

My problem is, that when the player moves outside (if the bats are present inside), they should be present outside, too. But, in the current set up, the bats are absent whenever you go outside or whenever you step inside (from outside). This is a problem because, later in the game, the absence or presence of bats will either prevent or allow the player to do something to progress the game. If a player notices this, they can obviously go inside to outside to inside, etc, to take advantage of at least one turn when there are no bats present. This is a no-no.

My solution would be this: go into every "inside" room that has an "outside" exit and add a script that moves the bat objects to the outside room before entering the room if the flag 'presentin' has been set. Of course, I would have to do the same thing all over again if bats are present outside when I go inside. This seems like an awful lot of work and I would like an answer or suggestions to simplify this before I start moving around to every room in the game adding scripts so...

my question... is there some sort of universal command that I can apply one time for moving inside and one time for moving outside that will carry with it the status of 'presentin' and 'presentout' flags so I do not have to add scripts for every room where this applies?!? Something in code that is a translation of "if the 'presentout' flag is set, then set flag 'presentin' whenever the flag 'inside' gets set on the player." I think the answer is right in front of me but after thinking of alternate solutions, I keep finding problems with it.

And... Does any of that make sense?

Thanks in advance!

HegemonKhan
probably the best way, would be to change the scripting for the compass' "in" and "out" exit choices... setting your 'indoor~outdoor' flag appropriately.

the only other way I can think of right now... is to give all of your rooms a flag for whether it is an inside room or an outside room, which you can then check upon it and adjust your other flag of being 'indoor' or 'outdoor', for your scripting. Or, you could just use the checking of the rooms' flag, not needing the flag of being 'indoor' or 'outdoor', as if you're in an 'inside' room, you're obviously inside, and if you're in an 'outside' room, you're obviously outside. But, depending on your game design, you may very well need that other flag of being 'indoor' vs 'outdoor'. So, it depends on how you're designing your game.

The method above has some different ways to make it a lot less cumbersome, but it's still cumbersome compared to adjusting the scripting of the compass' directions of 'in' and 'out'.

there's probably better ways~designs than my use of flags for the rooms, that the good coders can provide, but I can't think of them of course, laughs.

XanMag
Also, based on the layout of the map, going in can be any of the cardinal direction. You go "inside" by going south into the shanty, for example. The "in"/"out" compass direction alteration would make it easier for sure, but, If I am on a dirt path and there are huts to the north and the south, then "in" could apply to both north and south, so I can't use 'in' in that case. Right?

HegemonKhan
ya, then you're going to ahve to use some kind of indicator (flag) to check, unless the good coders have a better design that's beyond my knowledge.

add a flag (String Attribute or Boolean Attribute) to all of your rooms, to indicate whether that room is an inside/indoor room or an outside/outdoor room

then, you need a checking script, such as maybe using the 'on entering any~all rooms' Scripting (I believe it's in one of the tabs for the Game Object):

if (Get-Attribute/String/Boolean (this, "indoor_or_outdoor_room") = "indoor/true") {
-> // your player flag, such as named: player.is_inside = true
} else { // if (Get-Attribute/String/Boolean (this, "indoor_or_outdoor_room") = "outdoor/false") {
-> // your player flag, such as named: player.is_inside = false

jaynabonne
Can you explain why you need two flags for "present"? If the bats are present, then it seems the player's "inside" flag could determine what to say.

Unless you need to track where the player was when the bats showed up...

As far as the inside/outside, perhaps instead of using a flag, you can simply determine whether the player is inside or not by what the current parent is. If you set a flag called "outside" on the each room that is outside for instance, then you could know whether a player is inside or out side by

outside = GetBoolean(player.parent, "outside")
inside = not outside

Then you don't need to track things. You can just query the environment whenever you want to know.

XanMag
I need "inside" flag to determine if Xanadu is inside a building. When the time of day changes, a message prints letting the player know something about the environment is different. When it changes to midnight, for example, if you're indoors, the player is locked in place unless they have a light source. Outside, a message prints indicating something different. Also, "inside" determines what message to print when bats arrive.

I'm getting confused now but I think I set up the "presentin" flag to handle commands the player might try when interacting with the bats. Like, if "presentin" flag is set, "listen to bats" would check to see if the bats were present (presentin), then what time of day it was, then if the player is inside (inside). There are responses for "bat commands" that vary based on three separate conditions - inside/outside, time of day, and whether the bats are even there or not.

So if a player goes outside and the bats were present outside while the player was inside, then the bats should be present when they step outside. Like I said earlier, I could use the 'before entering the room' option and check for all those conditions and set them appropriately as needed, but that seems like a mess. It would be something like this: if bats have flag "presentin", then if it is dusk, then if player is not "inside" then print appropriate message and "wave proper flags" ("presentout", not player "presentin", and player not "inside").

Does that make sense? I'll send the game code if needed. This may be a case that I'm so used to/comfortable using flags, I'm overlooking a much simpler solution, but I still think I need to check all three conditions when going from inside to outside.

Thanks.

jaynabonne
Given what you said:

There are responses for "bat commands" that vary based on three separate conditions - inside/outside, time of day, and whether the bats are even there or not.



and that I assume "whether the bats are even there or not" is your "present" condition, then I don't think you need to manage two flags for present. "Present when the player is in the building" is the same state as "present when the player is outside the building", now that you've broken the "inside" state out from that. You don't need both inside/outside and presentin/presentout - just inside/outside and present. At least it seems that way to me.

If so, then that would simplify your situation, as you don't need to migrate flags as the player moves around. You just need to know if the player is inside or not, and you could use what I suggested above to not even need to track that flag - just make it a condition of the rooms.

XanMag
I'll send the .aslx file when I get home and you can take a look and see if you're right. If you don't mind.

jaynabonne
Sounds good. :)

XanMag


Here's the .aslx file. If you explore the little bit that I have done, I am aware that 'talk to grumpy man' returns an error... I'm still working on script dictionaries. I'm also aware I need to hide the panes during the intro and make them appear once you reach the hut. Don't worry about that! :)

But, the main thing here is to look at the set up of the time of day (located on the 'twentyfourhours' object), the bats arriving and departing randomly (I believe that is attached to 'Random Bats TS', and the difference between the "inside" and outside returns ('inside' flag is on the player (Xanadu). I believe I just have the one "inside" room right now and that is the "hut". You might be able to enter other buildings but those scripts have not been altered to reflect "inside" yet. You should be able to figure out how to get out of the hut, but just in case... 'ask for a drink' and then 'drink drink'.

Thanks again!

jaynabonne
I'll check it out.

jaynabonne
I've looked it over a bit, and for at least what you have so far, it seems like the "presentin" variable is doing what you want. If you were going to add another, I think I'd need to see how you were going to use it.

As far as handling inside vs outside, I think the easiest way to handle it would be with some sort of type. For example, you could create a type called "Inside" or "InsideRoom" or whatever you want. Then, you'd assign that type to all the inside rooms. (Or conversely, create an "Outside" type and add it to all the outside rooms. It depends on which is fewer or which you prefer to do. Maybe you're ok with adding a type to even all your rooms!)

Assuming you add an "InsideType" type to your inside rooms, then you could have a function like:

<function name="PlayerIsInside" type="boolean">
return (DoesInherit(player.parent, "InsideType"))
</function>

Then use that everywhere you're currently checking GetBoolean(Xanadu, "inside"). Moving the inside/outside responsibility to the rooms means you don't have to explicitly set and clear an "inside" attribute on Xanadu. You just look to the room to see where you are. (That helps if you happen to ever teleport the player. You won't have to work out whether they're transitioning inside to outside or vice versa. The target room will just tell you.)

I hope that helps. I can look more if you wish. There were a couple of other things you could simplify (e.g. use the "random" text processor command instead of explicitly creating "north", "south", "east", etc strings with all those if/elses), but that will do for tonight. :)

XanMag
Okay. Thanks a ton. Some time today, I will sit down and try to add the "InsideType", but admittedly I have never tried using 'types' in my games. Now is a good time to learn I guess!

As far as the random directional commands... I assume you were looking at the "bats flying off to the ____"? If so, I really just did that to learn something new. If it's working the way I want (and I thing it is), I'm not messing with it!! :lol:

Thanks again!

XanMag
Okay...

Let me know if this is how it would work for Xanadu being "inside".

  <type name="xaninside">
<insideroom type="script">
SetObjectFlagOn (Xanadu, "inside")
</insideroom>
</type>


Then, I assign all rooms that are "inside" this object type, right? This would allow me to add all rooms to this object type so whenever 'Xanadu' is in one of these rooms the flag "inside" is set, yes?

Now... the whole goal is to have bats move to ALL outside rooms IF Xanadu is "inside". I want this because I want the bats outside if the player moves outside and IF they were present inside ("presentin").

So, I think I have a "presentin" conflict. Whenever bats are present when "xaninside" is true, I need the bats to be present outside as well. I cannot set the script that controls this to run on "presentin" because it will totally mess up my printed messages. So, my solution is this: If 'presentin' is true, then I'll need to create a "present" flag to be true as well. Then I need move "bats" to rooms that do NOT contain "xaninside" attribute AND where bats "present" is true. That way, "presentin" messages print as needed AND the bats are outside if Xanadu goes from inside to outside.

Note that different bat objects (average bat, bats, enormous bats) are present at different times of the day (dusk, evening, midnight, dawn). So, this would be an enormously complex if/else if script with nesting upon nesting...

What I currently have working:
A. I already have my time of day turn script set and it runs smoothly.
B. I have my random bats script working (bats arrive with frequencies related to the time of day, messages print when bats arrive/depart when Xanadu is inside/outside)... EXCEPT for when Xanadu transitions from inside to outside or outside to inside.

My point is (I think!??):
1. I need help scripting how to move the proper bats to NOT "xaninside" rooms (outside) whenever Xanadu is "inside" and vice versa.

2. Is there an easier way to set this up? I'm half tempted to scrap it and try to start over with all my F&%&!NG bat scripts, but if there is something easier than restarting, I'm all for it. Setting up what I have so far has taken a LONG time but it is the running theme of the entire game.



Thanks.

XanMag

HegemonKhan
if you're going to use Jay's method, than not quite XanMag:

the 'DoesInherit' checks if you have the Object Type Element's name itself added to the Object (as an 'inherited' Attribute):

<function name="PlayerIsInside" type="boolean">
return (DoesInherit(game.pov.parent, "xaninside"))

// you can replace 'game.pov.parent' with 'Xanadu.parent', if you want, though if you got other Player Objects that you switch to during your game, then you must use the 'game.pov.parent'. If you decide to change your Player's name to something else, then if you used 'Xanadu.parent', it'll obviously now produce an error (or won't work, won't do anything). Using 'game.pov.parent' is a great way to avoid all of these issues, though if you want to do stuff or apply stuff to only a specific Player Object, then you do NOT want to use the 'game.pov' for that situation, obviously.

</function>

<type name="xaninside">
</type>

<object name="example_room_x">
<inherit name="xaninside" />
</object>


-------

if you want to use the addition Attribute for your game design, then it's also not quite right (well you could do it your way but it requires a bit more complex code work):

directly add the attribute, instead of adding via a script

this is done by (see the code below):

// checks if the Object has the Object Type (as an 'inherited' Attribute), 'xaninside', :

<function name="PlayerIsInside" type="boolean">
return (DoesInherit(game.pov.parent, "xaninside"))

// you can replace 'game.pov.parent' with 'Xanadu.parent', if you want, though if you got other Player Objects that you switch to during your game, then you must use the 'game.pov.parent'. If you decide to change your Player's name to something else, then if you used 'Xanadu.parent', it'll obviously now produce an error (or won't work, won't do anything). Using 'game.pov.parent' is a great way to avoid all of these issues, though if you want to do stuff or apply stuff to only a specific Player Object, then you do NOT want to use the 'game.pov' for that situation, obviously.

</function>

// checks if the Object has the Boolean Attribute, 'inside', and if its value is, 'true', and then, if so, the Function returns 'true', which can then be used in a script, just like Jay's Function. Both Functions achieve the exact same thing, so here's the Function for checking the Boolean Attribute:

<function name="xxx" type="boolean">

return (GetBoolean (game.pov.parent, "inside"))

// you can replace 'game.pov.parent' with 'Xanadu.parent', if you want, though if you got other Player Objects that you switch to during your game, then you must use the 'game.pov.parent'. If you decide to change your Player's name to something else, then if you used 'Xanadu.parent', it'll obviously now produce an error (or won't work, won't do anything). Using 'game.pov.parent' is a great way to avoid all of these issues, though if you want to do stuff or apply stuff to only a specific Player Object, then you do NOT want to use the 'game.pov' for that situation, obviously.

</function>

// -----------------------------------------

// this is how to directly add the attribute:
//
// any Object that you give an Object Type to (via the 'inherited' Attribute), will get the Attributes in the Object Type, and your 'SetObjectFlagOn(Object_name, "inside")' Attribute 'inside', is just a Boolean Attribute, which can be, is, added this way in code (done within the Object Type of course):
//
// <attr name="Attribute's name" type="Attribute's type">Attribute's value</attr>
//
// <attr name="inside" type="boolean">true</attr>
//
// so... (see below)

<type name="xaninside">
<attr name="inside" type="boolean">true</attr>
</type>

// ----------------------------------------

<object name="example_room_x">
<inherit name="xaninside" />
</object>

jaynabonne
XanMag wrote:Okay...

Let me know if this is how it would work for Xanadu being "inside".

  <type name="xaninside">
<insideroom type="script">
SetObjectFlagOn (Xanadu, "inside")
</insideroom>
</type>


Then, I assign all rooms that are "inside" this object type, right? This would allow me to add all rooms to this object type so whenever 'Xanadu' is in one of these rooms the flag "inside" is set, yes?

Not quite. The idea of creating a type is that, instead of even needing an attribute on Xanadu, you simply check the type of the room you're in. For example, in the real world, you look around you to see if you're inside or not, not look deep inside yourself. :) Inside-ness is defined by where you are. Similarly, in your game, instead of having a state on Xanadu, you have the state be on the rooms, and then you just see what the state is for the room Xanadu happens to be in at that time.

XanMag wrote:
Now... the whole goal is to have bats move to ALL outside rooms IF Xanadu is "inside". I want this because I want the bats outside if the player moves outside and IF they were present inside ("presentin").

This is the part I keep getting confused about. Wouldn't you want the bats outside as well if they're present? As far as I know, "presentin" means "they became present when Xanadu was inside", but I still don't know why it matters where Xanadu was when the bats showed up. All that matters is that they're present. (Even what you say next doesn't help. :) )

XanMag wrote:So, I think I have a "presentin" conflict. Whenever bats are present when "xaninside" is true, I need the bats to be present outside as well.

Well, yeah, they're present, period. :)

XanMag wrote:
I cannot set the script that controls this to run on "presentin" because it will totally mess up my printed messages. So, my solution is this: If 'presentin' is true, then I'll need to create a "present" flag to be true as well. Then I need move "bats" to rooms that do NOT contain "xaninside" attribute AND where bats "present" is true.

I'm assuming here that "bats" is a single object that follows Xanadu? If so, then do you mean you need to move the bats into a room that Xanadu enters when they're present and he's outside?

XanMag wrote:
That way, "presentin" messages print as needed AND the bats are outside if Xanadu goes from inside to outside.

I think the transition from inside to outside is immaterial. If you move outside and then move to another outside room, you still need to move the bats. So it's not the inside-outside transition that matters - it's moving from anywhere into a room that happens to be outside when the bats are present. Is that correct?

XanMag wrote:
Note that different bat objects (average bat, bats, enormous bats) are present at different times of the day (dusk, evening, midnight, dawn). So, this would be an enormously complex if/else if script with nesting upon nesting...

You can simplify this by having a "current_bats" attribute somewhere, maybe on the game object. You would set that to average bats, bats or enormous bats depending on the time of day (probably in your turn script), and then just reference "game.current_bats" everywhere instead of checking the time of day every time you need to manipulate the bats.

XanMag wrote:
What I currently have working:
A. I already have my time of day turn script set and it runs smoothly.
B. I have my random bats script working (bats arrive with frequencies related to the time of day, messages print when bats arrive/depart when Xanadu is inside/outside)... EXCEPT for when Xanadu transitions from inside to outside or outside to inside.

My point is (I think!??):
1. I need help scripting how to move the proper bats to NOT "xaninside" rooms (outside) whenever Xanadu is "inside" and vice versa.

2. Is there an easier way to set this up? I'm half tempted to scrap it and try to start over with all my F&%&!NG bat scripts, but if there is something easier than restarting, I'm all for it. Setting up what I have so far has taken a LONG time but it is the running theme of the entire game.

Thanks.

XanMag


If you can either confirm or clear up the questions I have above, then we can take a step closer to having this resolved. Once I have a good idea what you're trying to do, then I think the code should follow.

jaynabonne
A thought: if you do just need to move the bats into any outside room Xanadu moves into when they're present, then you should create an "outside" room type instead. Then we can give that type an "enter" script which will fire whenever Xanadu enters the room. It should be straightforward then to see if the bats are "present", and if they are, then just move the current bats into that room. That way, they will automatically follow Xanadu around outside.

XanMag
Haha... looks like I've confused more people than just myself!

Before I try and clarify those questions, I will point out now that the bats are not actually present (meaning in the room) with Xanadu. They can be heard scurrying, chewing, and flapping just outside. The "presentin" flag shows up to mark that they can be heard, but not actually seen (the flag name is a bit misleading). I have that flag appear when they arrive also so that random messages show up and messages show up when they arrive or depart. Those messages vary also depending on time of day indicated by a flag.

So, an example script in non-code would be... If 'twentyfourhours' has flag 'midnight', then if 'Xanadu' has flag 'inside', then if object attribute 'presentin' for bats2 equals true, then if random chance equals 5% then print message "The hellish bat-composed percussion beyond the walls has faded for now." and set bats2 attribute 'presentin' to false. And that is just part of that one script. The code view of the entire 'midnight' script is below. There are four scripts similar to this that run for each time of day.

if (GetBoolean(twentyfourhours, "midnight")) {
if (GetBoolean(Xanadu, "inside")) {
if (bats2.presentin = true) {
if (RandomChance(5)) {
msg ("<br/>The hellish bat composed percussion beyond the walls has faded for now.")
bats2.presentin = false
}
}
else {
if (RandomChance(95)) {
msg ("<br/>The gnawing, clawing, and shrieking bats seem to reverberate through the walls and into the room.")
bats2.presentin = true
}
}
}
else {
if (bats2.presentin = true) {
if (RandomChance(5)) {
msg ("<br/>The sky above silences as the bats disappear in pursuit of some unfortunate prey.")
MoveObject (bats, Item Warehouse)
bats2.presentin = false
MoveObject (bats2, Item Warehouse)
MoveObject (small bats, Item Warehouse)
MoveObject (large bats, Item Warehouse)
MoveObject (enormous bats, Item Warehouse)
}
}
else {
if (RandomChance(95)) {
msg ("<br/>The screeching above you is about all you can hear and the sky above you looks like a black, rippling ocean.")
MoveObjectHere (bats)
bats2.presentin = true
MoveObjectHere (bats2)
MoveObjectHere (small bats)
MoveObjectHere (large bats)
MoveObjectHere (enormous bats)
}
}
}
}

jaynabonne
Yes, I get that part. It's what happens when Xanadu is outside that is causing the grief. :)

For example, in the code above, when the bats are not "presentin" and your RandomChance(95) fires, then you move all the bats into the same room as the player. Perhaps that's the code that's wrong...

XanMag

This is the part I keep getting confused about. Wouldn't you want the bats outside as well if they're present? As far as I know, "presentin" means "they became present when Xanadu was inside", but I still don't know why it matters where Xanadu was when the bats showed up. All that matters is that they're present. (Even what you say next doesn't help. :) )



I hope my... better?... description of "presentin" helps clarify these two points of confusion you have.

I'm assuming here that "bats" is a single object that follows Xanadu? If so, then do you mean you need to move the bats into a room that Xanadu enters when they're present and he's outside?



Unfortunately, bats are not a single object. Below are my bats:
"bats" = present at dawn, evening, and midnight
"average bat" = single bat present at dusk only
"bats2" = comprised of two types of bats (large and small) and are present at midnight only
"enormous bats" = present at midnight only

If you look at it from a time of day perspective (don't know... might be helpful?)
dawn = "bats" only
dusk = "average bat" only
evening = "bats" only
midnight = "enormous bats", "bats2", and "bats"

I think the transition from inside to outside is immaterial. If you move outside and then move to another outside room, you still need to move the bats. So it's not the inside-outside transition that matters - it's moving from anywhere into a room that happens to be outside when the bats are present. Is that correct?



Yes... I think. If the bats can be heard and not seen (when the player is inside ("presentin")), I need to know how to make them appear outside when the player moves outside AND, for that matter how to carry the present state of the bats when moving between inside rooms. I also need to carry the present state of the bats when transitioning from room to room when the player is outside.

You can simplify this by having a "current_bats" attribute somewhere, maybe on the game object. You would set that to average bats, bats or enormous bats depending on the time of day (probably in your turn script), and then just reference "game.current_bats" everywhere instead of checking the time of day every time you need to manipulate the bats.



Does this proposal answer the question I had above? I think that might solve my dilemma when the bats are outside and I move from room to room, but what about inside when there aren't any bats actually present? Two "current bats" attributes - one for responses inside and one for outside?

Thanks.

XanMag
jaynabonne wrote:Yes, I get that part. It's what happens when Xanadu is outside that is causing the grief. :)

For example, in the code above, when the bats are not "presentin" and your RandomChance(95) fires, then you move all the bats into the same room as the player. Perhaps that's the code that's wrong...


Hopefully in that long-worded post above this is corrected.

Perhaps I should have named the flag "presencein" or "presenceknown" to reflect their true state! :P

When that 95% chance fires, they become audible to the player while they are inside, but they, themselves (as actual objects) are not actually there.

> x bats
You can hear them outside, but none can be seen in the room with you. Thankfully.

> listen to bats
The bats are making bone chilling sounds outside. There must be quite a few because you can hear them collectively gnawing and clawing at the walls and screeching amongst them selves.

jaynabonne
I think I have a general idea what you want to do. It's a bit late now, but the weekend is upon us soon. Let me see if I can take a stab tomorrow at putting something together.

Edit: I think if we can distribute the logic a bit, it might make it easier to track. For example, it might make sense to put a "changed" script on "presentin", so that when you set it to true or false, you can then catch the change and then handle things. (That also might not make sense. I'll think about it some more.) But the idea is to see if we can break the code up a bit and have it handled more discretely, rather than all in one place.

Another example is handling the moving of the bats based on the room movement rather than in the turn script, as I had proposed before. We'll see how it all pans out. :)

jaynabonne
I'm going to work on this tonight (assuming nothing dire comes up), but I had a question come up while thinking of situations. If you have an answer, great. If not, I'll make something up. :)

Let's say you're outside and the bats-of-the-hour shows up (bats, enourmous bat, whatever). Now let's say you're wandering around or inspecting things or just typing "z" over and over to wait, and you remain outside and the time of day changes, say from morning to afternoon, when a different type of bat is supposed to reign.

What should happen? I can think of a few possibilities:
1) The current bat thingy goes away. If at some point in the future, the percentages are right, the new bat fiend will show up.
2) The current bat thingy goes away, and the new one shows up to replace it.
3) The current bats stay until they would normally go away, based on the percentages.

I'm tempted to go with the first or third, as it makes more sense (I think) from a reality point of view. As opposed to the second, where they seem to be in shifts or operating as a tag team...

XanMag
I'm about 93.8% sure that I have it scripted so that all current bats disappear at the end of midnight (for example) and the new bats come in at the set random percent for dawn. I'll let you know if that is different when I get back home. Any option above is nice except for number three. For game design reasons, I can't have some of those bats stick around. So, your #1 above is how I have it set up and I am okay with that.

Let me know if that doesn't make sense! Thanks!

jaynabonne
I have a good chunk of this done, but I need to wrap up some more loose ends and make sure it all works. So... sometime tomorrow, I'm hoping. (Well I will post what I have regardless.)

You threw me a curve by having two time intervals mapped to "dawn". But I'm managing. :lol:

XanMag
Oh boy... Along with some guilt, I've a feeling of intrigue to see what you come up with.

jaynabonne
So here's a first attempt. Be sure you don't overwrite your existing game with this. :) At least, not yet. I'd put the code inline for those not wanting to download the file, but it's too much text for the website to allow. So snippets below.

What you will notice now is that there are a lot fewer "if"s than there were before. I did this by creating objects for the various times of day and moving functionality and data onto them. For example, "evening" looks like this:

    <object name="evening">
<dirtpathdescription>The market to the east is completely deserted, save the bats.</dirtpathdescription>
<bats type="object">evening bats</bats>
<startinside type="script">
MsgWithBr ("The room has grown quite cold. Despite the growing darkness in the room, you can see a cloud of microscopic water crystals every time you exhale.")
</startinside>
<startoutside type="script">
MsgWithBr ("The sun has fully retreated leaving the dark sky and the stars to keep you company. It is quite chilly out here now.")
</startoutside>
</object>


That keeps you from having to check the current time of day all over the place. You just request the information you need from the current time of day. The code handling the time now simply sets the "currenttime" attribute to the desired object, and the rest of the code feeds off of that. (There's even a changed script for "currenttime" that handles outputting the correct description and updating what the current bats should be.)

    <changedcurrenttime type="script">
Setcurrentbats (this.currenttime.bats)
if (XanaduIsInside()) {
do (this.currenttime, "startinside")
}
else {
do (this.currenttime, "startoutside")
}
</changedcurrenttime>

One critical piece now is that each time of day can have a "bats" attribute, which points to the bats object that should show up at that time of day. I had to add another one - dawn and evening were sharing the original "bats" object, but the behavior was different. So I broke it out to separate "dawn bats" and "evening bats" objects. Since they had so much in common, I also broke the common bits out to a "batsbase" type.

I also renamed "bats2" to "evening bats", since it fit the new pattern and seemed more descriptive.

Each of the bats objects now hold the text to show when they arrive or leave (both inside and outside) as well as the arriving and leaving chances used in the random code. This allows the code to reduce down to the common structure, without all the special cases. This is your bats turn script now:

  <turnscript name="Random Bats TS">
<enabled />
<script>
if (not GetAttribute(game, "currentbats") = null) {
if (BatsArePresent()) {
if (RandomChance(game.currentbats.leavechance)) {
BatsLeave
}
}
else {
if (RandomChance(game.currentbats.arrivechance)) {
BatsArrive
}
}
}
</script>
</turnscript>

As you can see, it is the essence of what you had duplicated for each case, now driven by the currentbats. No need to check all the different types, as the currentbats handles that for you.

Bats have additional fields now like this, which are used to generally handle things related to them (this is for the "dawn bats"):

      <arrivechance type="int">80</arrivechance>
<leavechance type="int">20</leavechance>
<arriveinside>A terrible chewing and scuttling noise can be heard from beyond the outermost wall.</arriveinside>
<leaveinside>The incessant gnawing and flapping outside have subsided for now.</leaveinside>
<arriveoutside>As if by command, the bats are flying in unison toward the northern horizon.</arriveoutside>
<leaveoutside>The shrieking bats have disappeared into the northern dawning sky.</leaveoutside>

If you have any questions, feel free to ask. I think I have one bit of behavior change: when the bats leave at the change of time of day, they now announce their departure, as they would otherwise. That differs from what you had before, where the bats would suddenly be gone.

And after all that, if you move around outside while the bats are present, they continually move to where Xanadu is:

  <type name="Outside">
<enter type="script">
if (BatsArePresent()) {
BatsFlyToXanadu
}
</enter>
</type>

I hope the code is set up now in a way that is easier to maintain. If nothing else, you can see all the attributes for a particular time of day in one place (including the add-on description for the dirt path). So you can see if things look they way you want without your brain getting all fuzzy. :) There were a couple of errors in your original code that have gone away during this consolidation.

To start with the code, check out the various time of day objects and the bat ones. You'll see where all your text went.

jaynabonne
Oh, by the way, I moved Xanadu to start in the hut instead of the title screen. Otherwise, I would have gone insane waiting almost two minutes to get to anything each time I ran it. :) You can move it back as you wish.

Also you had bat objects that weren't used (large bats, small bats, enormous bats). They were moved to the Item Warehouse but never out of it. Not sure what was supposed to happen with those. Maybe work in progress...

XanMag
I'm forever in your debt! I look forward to implementing it the next time I sit in front of the computer! Infinite Thanks!

XanMag
Okay... All seems much better now. After rummaging through the GUI, I think I have located all of the things I need. I'm still unsure how what is seen in the GUI translates into what is happening in the game, but when I look at it in code, I at least can understand what you did to make those things happen. Perhaps this is why I've heard the code coders hear say it's easier to write in code than use the GUI specifically. :lol:

Anyway, I have two questions...

jaynabonne wrote: Also you had bat objects that weren't used (large bats, small bats, enormous bats). They were moved to the Item Warehouse but never out of it. Not sure what was supposed to happen with those. Maybe work in progress...


1. I initially had them move to the outside room that Xanadu was in when they arrived so that the player could look at them individually. Then when I had the bats leave, I moved them out. Without mucking up what you have created so far, is there a way that I can easily make them visible when they are present? Currently, at midnight, when the player types 'x enormous bats' they get the response that they cannot see that when obviously they should be able to see that based on the 'x bats' description. It's kind of a nit-picky thing, but I would like them to be visible for inspection.

Could I just add a move object [insert bat type here] script to the function below when they arrive and then add a move them to the 'Item Warehouse' script when they leave? And, if I do that, will they "follow" Xanadu like they are supposed to when he changes outside rooms (or will I have to also move them as well with Xanadu as you did the 'bats')?
if (not GetAttribute(game, "currentbats") = null) {
if (BatsArePresent()) {
if (RandomChance(game.currentbats.leavechance)) {
BatsLeave
}
}
else {
if (RandomChance(game.currentbats.arrivechance)) {
BatsArrive
}
}
}


2. When Xanadu is inside, he should not be able to see the bats, only hear them. Currently the bats are indoors with Xanadu. I could easily make them invisible when Xanadu goes inside any "inside room". I don't know that option will work however because I'd like an 'x bats' input to return something like "Thankfully, you can see no bats here, but you certainly can hear them outside." Also, I think with what you have done with the bats, there is probably a much easier way to do it than what my hack solution would be.

Does that make sense? Sorry to be a pest!

Thanks again!

jaynabonne
1. Yes, I see I messed that up a bit... Let me think about that a bit, because I don't think you want them to always show up, but only at midnight (at least the code I finally saw just now seemed that way). Somehow we need to group them together. It's a shame the "evening bat" couldn't be a container or something that held the other three but exposed them to the room somehow.

2. A bug there as well. It should work if you change this:

  <function name="BatsArrive">
if (not BatsArePresent()) {
game.batspresent = true
SayBatText ("arrive")
BatsFlyToXanadu
}
</function>

to this:

  <function name="BatsArrive">
if (not BatsArePresent()) {
game.batspresent = true
SayBatText ("arrive")
if (not XanaduIsInside()) {
BatsFlyToXanadu
}
}
</function>

It just needs to make sure Xanadu isn't inside. (I always tested this outside. Go figure... :lol: )

jaynabonne
Actually, that seems to work for 1. So drag the three bats (large, small and enormous) inside "evening bats". Then click on "evening bats", and turn on "Container" under the Features tab. Then on the "Container" tab, set the Container Type to "Surface". Don't check either of the check boxes.

Now you can "x" the various "sub bats" whenever the evening bats are in the room.

Now, the way the bats are set, the large and small bats are scenery whereas "enormous bats" is not. So "enormous bats" shows up in the current list in the right pane whereas the others do not. Assuming you want them to be the same, then either set "enormous bats" to scenery, or take scenery off the other two, depending on whether you want them in the list or not.

XanMag
Perfect and easy solution! Thanks again!

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

Support

Forums