Calling multiple attributes = xyz at a time?
XanMag
11 Feb 2017, 02:29I could solve this by adding a bunch of 'Else If's and swapping out dawn with morning, noon, and afternoon, but I'm sure I will need to have an answer to this eventually so...
I have seven different parts of the day that get cycled as turns are taken. I would like to be able to add descriptions to certain objects depending on what period of day it is. My current code is this:
if (twentyfourhours.currenttime = dawn) {
msg ("The dozens of villagers here aren't really doing a lot of shopping. They are milling around, engaged in light-hearted conversation.")
}
What can I do to include dawn, morning, noon, and afternoon to this script so I can avoid doing an 'else if' for each scenario? The printed message is the same for each of those parts of day. At dusk, evening, and midnight, those descriptions will change and will be placed in an 'else if'.
Thanks in advance!
The Pixie
11 Feb 2017, 08:58One way wouild be to put a flag on those rooms, and then on the game object, in the script that runs when the player enters a room, check if that flag is set, and then do the above code.
Alternatively, put the code in a function, and have those rooms call the function.
As for the code, you could use a select
command, or text processor commands. Or put the text in a string list, and assign each part of the day a number, 0 to 6, and select from the list based on that (I think that would be my choice). Or have a function that returns a number based on twentyfourhours.currenttime
, and use that to select from the string list.
hegemonkhan
11 Feb 2017, 09:00there's a few different ways to do this:
just re-arranging your scripting:
(if I understood your post), your 'dusk', 'evening', and 'midnight' don't share the same responses to each other:
if (twentyfourhours.currenttime = "dusk") {
// blah
} else if (twentyfourhours.currenttime = "evening") {
// blah
} else if (twentyfourhours.currenttime = "midnight") {
// blah
} else { // presuming only 'dawn', 'morning', 'noon', and 'afternoon' remain:
msg ("The dozens of villagers here aren't really doing a lot of shopping. They are milling around, engaged in light-hearted conversation.")
}
-------------------------------
// if your 'dusk', 'evening', and 'midnight' do share the same responses to each other:
if (twentyfourhours.currenttime = "dusk" or twentyfourhours.currenttime = "evening" or twentyfourhours.currenttime = "midnight") {
// blah
} else { // presuming only 'dawn', 'morning', 'noon', and 'afternoon' remain:
msg ("The dozens of villagers here aren't really doing a lot of shopping. They are milling around, engaged in light-hearted conversation.")
}
using Dictionary Attributes (using a String Dictionary for the example):
(Pixie and Jay, probably know a way of using a VARIABLE to hold your same response (for dawn/morning/noon/afternoon), and apply/incorporate it to/into the dictionary's items of dawn, morning, noon, afternoon. I'm still not capable/understanding of the way that this can be done, so I've got to copy and paste the same response for each of them)
<object name="twentyfourhours">
<attr name="currenttime" type="string">unknown</attr>
</object>
<object name="hour_data_object">
<attr name="hour_stringlist_attribute" type="simplestringlist">dawn; morning; noon; afternoon; dusk; evening; midnight</attr> // I just added this List Attribute out of habit/completeness, as it's usually useful/needed, as something in your game will probably need a list of your hour strings, but this is not needed in any way for this (simple) example (as it stands now)
<attr name="hour_stringdictionary_attribute" type="simplestringdictionary">dawn = "blah for dawn"; evening = "blah for evening"; midnight = "blah for midnight"; dusk = "The dozens of villagers here aren't really doing a lot of shopping. They are milling around, engaged in light-hearted conversation."; morning = "The dozens of villagers here aren't really doing a lot of shopping. They are milling around, engaged in light-hearted conversation."; noon = "The dozens of villagers here aren't really doing a lot of shopping. They are milling around, engaged in light-hearted conversation."; afternoon = "The dozens of villagers here aren't really doing a lot of shopping. They are milling around, engaged in light-hearted conversation."</attr>
</object>
// scripting:
string_variable = StringDictionaryItem (hour_data_object.hour_stringdictionary_attribute, twentyfourhours.currenttime)
msg (string_variable)

DarkLizerd
18 Mar 2017, 04:57Switch is an alternative, and an improvement over if, else if chains...
and may be easer to work with...
Still learning my self...
hegemonkhan
18 Mar 2017, 10:34'switch/case/default' and 'if/else if/else' blocks/functions are exactly the same functionally (barring me testing just how much expression/scripting the 'switch/case' blocks/functions is programmed to handle/parse compared to that of the 'if/else if' block/function), so it's really just a matter how which design/look you like the best and/or for that type of code design you're doing.
Silver
18 Mar 2017, 15:24I would set true/false flags for the time of day then use the text processor.
{if time.morning:it is morning}
{if time.afternoon:it is afternoon}
{if time.evening:it is evening}
Note: you'll need to create an object called time to handle the coding.
I have a room in my game that is light or dark. It adds a massive amount of work changing just that one thing - all objects neeed to have variables not just the room description.