A text Myst Online project

General debates and discussion about the Guild of Writers and Age creation

Re: A text Myst Online project

Postby belford » Mon Aug 26, 2013 8:40 pm

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.
belford
 
Posts: 344
Joined: Sat Sep 29, 2007 7:18 pm

Re: A text Myst Online project

Postby belford » Mon Aug 26, 2013 10:19 pm

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]".
Last edited by belford on Wed Aug 28, 2013 10:10 pm, edited 1 time in total.
belford
 
Posts: 344
Joined: Sat Sep 29, 2007 7:18 pm

Re: A text Myst Online project

Postby KathAveara » Wed Aug 28, 2013 2:16 pm

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!
Moula KI: 17967159
DI KI: 00205116
deviantART: kathaveara
tumblr: kaththedragon

Grand Master of the Guild of Linguists
KathAveara
 
Posts: 79
Joined: Mon Jun 10, 2013 2:29 am

Re: A text Myst Online project

Postby KathAveara » Wed Aug 28, 2013 4:05 pm

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
KathAveara
 
Posts: 79
Joined: Mon Jun 10, 2013 2:29 am

Re: A text Myst Online project

Postby belford » Wed Aug 28, 2013 10:05 pm

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()".
belford
 
Posts: 344
Joined: Sat Sep 29, 2007 7:18 pm

Re: A text Myst Online project

Postby KathAveara » Thu Aug 29, 2013 1:42 am

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?
Moula KI: 17967159
DI KI: 00205116
deviantART: kathaveara
tumblr: kaththedragon

Grand Master of the Guild of Linguists
KathAveara
 
Posts: 79
Joined: Mon Jun 10, 2013 2:29 am

Re: A text Myst Online project

Postby KathAveara » Thu Aug 29, 2013 2:00 am

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
KathAveara
 
Posts: 79
Joined: Mon Jun 10, 2013 2:29 am

Re: A text Myst Online project

Postby belford » Thu Aug 29, 2013 8:35 am

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.
belford
 
Posts: 344
Joined: Sat Sep 29, 2007 7:18 pm

Re: A text Myst Online project

Postby KathAveara » Thu Aug 29, 2013 9:48 am

Ok, here's my code.

The property 'seconds' is defined through the code:
Code: Select all
(datetime.now - datetime.datetime(2013,8,28,hour=18)).total_seconds()

In another property, I have the line:
Code: Select all
seconds % 56976

which raises the exception "TypeError: unsupported operand type(s) for %: 'dict' and 'int'"

Tell me what I'm doing wrong.
Moula KI: 17967159
DI KI: 00205116
deviantART: kathaveara
tumblr: kaththedragon

Grand Master of the Guild of Linguists
KathAveara
 
Posts: 79
Joined: Mon Jun 10, 2013 2:29 am

Re: A text Myst Online project

Postby belford » Thu Aug 29, 2013 10:29 am

You want
Code: Select all
seconds() % 56976


I've also added a couple of time-related examples to the code-samples section of the wiki.
belford
 
Posts: 344
Joined: Sat Sep 29, 2007 7:18 pm

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron