Trying to make a time stamp for the Journal [SOLVED]
Curt A. P.
10 Apr 2019, 16:45I have a journal which has also the basic functionality from the the Journal tutorial in the documentation. I add certain events in the story as text to a stringlist and everything works fine but I want to add a time stamp to each entry.
I just can't figure how to get the current day and time value into the entry. I can add the value into the entry but the problem is if I read the journal again later, it always displays the current timeand not the when the entry was added.
mrangel
10 Apr 2019, 19:43How are you adding the timestamp?
If it displays the current time, I wonder if you're using text processor directives; those are only evaluated when they're displayed. If so, you could call the ProcessText
function manually when you add a string to the journal, causing the text processor to be run then.
Curt A. P.
10 Apr 2019, 23:35How are you adding the timestamp?
You're right, this was the text processor. My previous attempts to make to turn the values into strings returned a error:
d = ToString(game.day)
"Error running script: Error evaluating expression 'ToString(game.day)': Object reference not set to an instance of an object."
If so, you could call the ProcessText function manually when you add a string to the journal, causing the text processor to be run then.
How does it work? I couldn't get much from the documentation's explanation.
mrangel
11 Apr 2019, 00:52It's simple. If you have a string s
, then you can do:
s = ProcessText (s)
That will cause any text processor directives in the string s to be replaced by their output, based on the current values of any variables they use.
If you need more help with this, it might be worth sharing the code you're using. I don't know the tutorial you're using.
Curt A. P.
11 Apr 2019, 03:34I used this tutorial for the entries: http://docs.textadventures.co.uk/quest/keeping_a_journal.html
The entries are in a stringlist.
plr_journal.entries = NewStringList()
list add(plr_journal.entries, "I found Moira and she wasn't happy. She gave me the missng book and I spared her life.")
I have a Journal menu in which the player can select "Read Entries" (also as a command).
To print the entries I print a message with FormatList in it.
msg ("</br>> read Journal Entries </br>" + FormatList(plr_journal.entries, "</br></br>", "</br></br>", "The Journal is empty.</br>") + "")
This prints like this:
> read Journal Entries
I have finally reached the catacombs.
I found Moira and she wasn't happy. She gave me the missng book and I spared her life.
I thought adding a time stamp each entry would look nicer but I couldn't figure it yet. Also I still don't understand how to use ProcessText. Does it need the text processor function or a string value? The time values are all integers and any attempt to use ToString results in a error.
mrangel
11 Apr 2019, 08:11You said you had it working but it displayed the current time when the journal entry was displayed.
So I assume you have a line something like:
list add(plr_journal.entries, "[Day {game.day}, {game.hour}:{game.minute}] I found Moira and she wasn't happy. She gave me the missng book and I spared her life.")
If you've got something like that, then you can simply change it to:
list add(plr_journal.entries, ProcessText ("[Day {game.day}, {game.hour}:{game.minute}] I found Moira and she wasn't happy. She gave me the missng book and I spared her life."))
Or you could put a string together directly:
journal_message = "Day " + game.day + ", " + game.hour + ":" + Right("0"+game.minutes, 2) + " - I found Moira and she wasn't happy"
list add (plr_journal.entries, journal_message)
Curt A. P.
11 Apr 2019, 18:34Hahaha... Yes, pretty much like that.
list add(plr_journal.entries, "<b>Day: {game.day}, {game.hour}:{game.minute}</br>Turn: {game.turncount}</br></b> I found Moira and she wasn't happy. She gave me the missng book and I spared her life.")
I gonna test it later, thanks...
Curt A. P.
11 Apr 2019, 22:05So, both variations doesn't print a value...
list add(plr_journal.entries, ProcessText ("[Day {game.day}, {game.hour}:{game.minute}] I found Moira and she wasn't happy. She gave me the missng book and I spared her life."))
and
journal_message = "Day " + game.day + ", " + game.hour + ":" + Right("0"+game.minutes, 2) + " - I found Moira and she wasn't happy"
list add (plr_journal.entries, journal_message)
Pirnt this:
[Day: Time: : Turn: ]
mrangel
11 Apr 2019, 22:15What are game.day
and game.hour
set to at this point?
Are you sure they're set to something?
Curt A. P.
11 Apr 2019, 23:02They are all integer values and before I made my last post I have tested it with different values, but only integers.I think that's why I tried ToString in the first place... using a copy of your code brought the same result... :-(
Edit: They are all integers because, unlike Pixie's Clock Lib I don't have named days. It's just a day counter. Game starts at Day 1 and the number just increase forever.
Curt A. P.
12 Apr 2019, 02:17I solved it!
After finally understanding what ToString exactly does the first try solved the error.
timestamp = "Day: " + ToString (GetInt (game, "day")) + ", Time: " + ToString (GetInt (game, "hour")) + ":" + ToString (GetInt (game, "minute")) + ""
list add (game.journal_entries, "" + timestamp + "Blablabla...")
I think I gonna set a game.timetamp attribute to a turnscript and use it whenever I write a journal entry...
Curt A. P.
12 Apr 2019, 15:44Hm, when I use the object attribute game.timestamp it doesn't print the time stamp in the message.
game.timestamp = "Day: " + ToString (GetInt (game, "day")) + ", Time: " + ToString (GetInt (game, "hour")) + ":" + ToString (GetInt (game, "minute")) + ""
list add (game.journal_entries, "" + game.timestamp + "Blablabla...")
while the same code with a variable works .
timestamp = "Day: " + ToString (GetInt (game, "day")) + ", Time: " + ToString (GetInt (game, "hour")) + ":" + ToString (GetInt (game, "minute")) + ""
list add (game.journal_entries, "" + timestamp + "Blablabla...")
Edit:
Okay, now I can use ProcessText (game.timestamp) in the journal entry in order to get around this and using the object attribute.
game.timestamp = "Day: " + ToString (GetInt (game, "day")) + ", Time: " + ToString (GetInt (game, "hour")) + ":" + ToString (GetInt (game, "minute")) + ""
list add (game.journal_entries, "" + ProcessText (game.timestamp) + "Blablabla...")
Tested it with the turnscript and it works.
Curt A. P.
17 Apr 2019, 17:23Just changed the whole stuff... Dunno how I never recognized that status attributes won't update if Don't use ! and now, after two years off developing... So, I've learned what a changescript is and got everything set up. That's fine but now I need in some cases Rounded Numbers to print for the player... in order to avoid messages like, "You've dealt 5,87538?12 DMG."
dalogumix
18 Apr 2019, 18:26Hi there, Are you a Home Depot employee? Do you need help logging into your myTHDHR account? Then this article is tailor-made for you.
https://employeelogin.xyz/mythdhr-login/