A text Myst Online project
Re: A text Myst Online project
Sorry about that. It's a filed work item ("List slices and splices") and I meant to get to it when I was adding insert, append, pop, and so on. But it slipped my mind.
I'll see if I can throw it in tomorrow.
I'll see if I can throw it in tomorrow.
Re: A text Myst Online project
Eh, easy fix. :) Simple subscripts are now assignable, e.g. "x[y] = 1" or "del x[y]".
The caveat about mutable properties remains, however. I haven't fixed that yet.
I also haven't implemented slices (i.e., "x[1:4]" or "y[1:]")
Note that property collections (players, locations, etc) can be referenced by subscript as well as by attribute. So the player property player.x can also be referred to as player["x"]. Assignments can be done this way.
EDIT-ADD: 3Phen points out that "x += [4]" works on a list, since it is logically equivalent to "x = x + [4]".
The caveat about mutable properties remains, however. I haven't fixed that yet.
I also haven't implemented slices (i.e., "x[1:4]" or "y[1:]")
Note that property collections (players, locations, etc) can be referenced by subscript as well as by attribute. So the player property player.x can also be referred to as player["x"]. Assignments can be done this way.
EDIT-ADD: 3Phen points out that "x += [4]" works on a list, since it is logically equivalent to "x = x + [4]".
Last edited by belford on Wed Aug 28, 2013 10:10 pm, edited 1 time in total.
-
- Posts: 79
- Joined: Mon Jun 10, 2013 2:29 am
Re: A text Myst Online project
I'm having some trouble with datetimes. Namely, I have this property timeelapsed which /eval returns as datetime.timedelta(num,num,num), where each num is a separate number. So far so good. But, when I try and do timeelapsed.total_seconds(), which the wiki says I can (and I presume is the total number of seconds stored in the timedelta), I get this error: Eval raised exception: ExecSandboxException: dict.total_seconds: getattr not allowed
It's breaking my garden Age! Please help!
It's breaking my garden Age! Please help!
Moula KI: 17967159
DI KI: 00205116
deviantART: kathaveara
tumblr: kaththedragon
Grand Master of the Guild of Linguists
DI KI: 00205116
deviantART: kathaveara
tumblr: kaththedragon
Grand Master of the Guild of Linguists
-
- Posts: 79
- Joined: Mon Jun 10, 2013 2:29 am
Re: A text Myst Online project
Do we have str.split() in Seltani yet?
Moula KI: 17967159
DI KI: 00205116
deviantART: kathaveara
tumblr: kaththedragon
Grand Master of the Guild of Linguists
DI KI: 00205116
deviantART: kathaveara
tumblr: kaththedragon
Grand Master of the Guild of Linguists
Re: A text Myst Online project
Yes, str.split() works. Most of the methods on str objects are now available. (str.format is the major exception, because I'm not sure about new-style formatting yet. str % (arg, arg, arg) works.)
datetime.timedelta is *not* one of the DB-storable types (although datetime.datetime is). If you try to assign "timeelapsed = datetime.timedelta(1,2,3)" you'll get an "Cannot encode object" exception.
So you must be doing something else. Your exception is reporting "dict.total_seconds" as the problem, so timeelapsed must be a dict object of some sort. Typing "/getprop timeelapsed" should display it.
If you need to store a duration in the database, you should store the total_seconds() value. For example, if t1 and t2 are datetimes, then (t1-t2) is a timedelta. You can't assign "timeelapsed = (t1-t2)" but you could do "timeelapsed = (t1-t2).total_seconds()".
datetime.timedelta is *not* one of the DB-storable types (although datetime.datetime is). If you try to assign "timeelapsed = datetime.timedelta(1,2,3)" you'll get an "Cannot encode object" exception.
So you must be doing something else. Your exception is reporting "dict.total_seconds" as the problem, so timeelapsed must be a dict object of some sort. Typing "/getprop timeelapsed" should display it.
If you need to store a duration in the database, you should store the total_seconds() value. For example, if t1 and t2 are datetimes, then (t1-t2) is a timedelta. You can't assign "timeelapsed = (t1-t2)" but you could do "timeelapsed = (t1-t2).total_seconds()".
-
- Posts: 79
- Joined: Mon Jun 10, 2013 2:29 am
Re: A text Myst Online project
Ah! Thanks a bunch Belford!
Edit: New problem! I'm trying to take the mod (%) of the .total_seconds() value after assigning this to a property, but apparently I'm trying to take the mod of a dict. Sure enough, /getprop revealed that I am working with a dict. How to I convert this to an int?
Edit: New problem! I'm trying to take the mod (%) of the .total_seconds() value after assigning this to a property, but apparently I'm trying to take the mod of a dict. Sure enough, /getprop revealed that I am working with a dict. How to I convert this to an int?
Moula KI: 17967159
DI KI: 00205116
deviantART: kathaveara
tumblr: kaththedragon
Grand Master of the Guild of Linguists
DI KI: 00205116
deviantART: kathaveara
tumblr: kaththedragon
Grand Master of the Guild of Linguists
-
- Posts: 79
- Joined: Mon Jun 10, 2013 2:29 am
Re: A text Myst Online project
Also, could the books on a bookstand be optionally reorderable?
Moula KI: 17967159
DI KI: 00205116
deviantART: kathaveara
tumblr: kaththedragon
Grand Master of the Guild of Linguists
DI KI: 00205116
deviantART: kathaveara
tumblr: kaththedragon
Grand Master of the Guild of Linguists
Re: A text Myst Online project
timedelta.total_seconds() is a float. You can use % on floats. I don't know how you're getting dicts in your properties, but however you're doing it, that's your mistake.
Reordering books is a filed bug.
Reordering books is a filed bug.
-
- Posts: 79
- Joined: Mon Jun 10, 2013 2:29 am
Re: A text Myst Online project
Ok, here's my code.
The property 'seconds' is defined through the code:
In another property, I have the line:
which raises the exception "TypeError: unsupported operand type(s) for %: 'dict' and 'int'"
Tell me what I'm doing wrong.
The property 'seconds' is defined through the code:
Code: Select all
(datetime.now - datetime.datetime(2013,8,28,hour=18)).total_seconds()
Code: Select all
seconds % 56976
Tell me what I'm doing wrong.
Moula KI: 17967159
DI KI: 00205116
deviantART: kathaveara
tumblr: kaththedragon
Grand Master of the Guild of Linguists
DI KI: 00205116
deviantART: kathaveara
tumblr: kaththedragon
Grand Master of the Guild of Linguists
Re: A text Myst Online project
You want
I've also added a couple of time-related examples to the code-samples section of the wiki.
Code: Select all
seconds() % 56976