Want to see more players? Then digg it!

Forum :: Mods :: From the never-ending pool of Eckels' inane programming questions, comes another one...

Sign In

You must sign in to post.

From the never-ending pool of Eckels' inane programming questions, comes another one... :: May 11, 2007 @ 11:49am
Ensign eckels
Joined: Mar 4, 2007
Posts: 200
ok here's my situation - I've combined the random map generating code from classic.py with edit.py to give the editor a random map generator.

The good news is it works. Mostly.

The bad news is it doesn't all work.

It does what it's supposed to do, generate a random map. But to get it to work, i had to comment out this code from the original edit.py:

       # if self.fname != '':
        #    self.do_load()

With that code out, I can at least get the program a random map, which I can edit and play. I just can't save or load anything, or else it crashes. If I leave the above code in, it crashes on load.

The error is always TypeError: expected string or buffer.

If I uncomment that line, and run it so it crashes on startup, it points to line 281, in do_load:

    def do_load(self):
        fname = self.fname
        data = galcon.file_load(fname) ## this line
        mapfile.fromstring(self,data)

If I comment the line, and run it so that it crashes when I try to save, it points to line 286, in do_save

    def do_save(self):
        fname = self.fname
        if not galcon.file_check_name(fname): ## this line
            return dialog.Pause(self.game,'invalid file name: %s'%fname,self.state)
        data = mapfile.tostring(self)
        galcon.file_save(fname,data)

so I can see that it's galcon.file_check_name(fname) that's causing a problem, and it's obviously interfering with the random map generator code.

I just can't figure out for the life of me what it's interfering with. It's because the file_check_name is where the problem is occuring, but I don't know how it works, since it's outside of the files I can view... so can someone work out with me on how I screwed up this code?
Re: From the never-ending pool of Eckels' inane programming questions, comes another one... :: May 11, 2007 @ 2:51pm
Ensign thirdparty
Joined: Dec 20, 2006
Posts: 279
Location: Eastern U.S.A.
I've been planning to do that myself.  (I just started tinkering around today.  So far I've updated the end-of-game rules in classic mode to match those of net play: you can have no planets and only ships, but not for more than thirty seconds.  A generator for the map editor is high on my priority list.)  When I do, I'll post my code.

At a guess, it sounds like you've got garbage in your fname variable.  Are you sure that you've correctly initialized your Edit_ object?
Re: From the never-ending pool of Eckels' inane programming questions, comes another one... :: May 11, 2007 @ 3:21pm
Ensign eckels
Joined: Mar 4, 2007
Posts: 200
At a guess, it sounds like you've got garbage in your fname variable.  Are you sure that you've correctly initialized your Edit_ object?


class Edit_(galcon.State):
    def __init__(self,game,parent=None,fname=None,data=None):
        self.game = game
        self.fname = fname
        self.hover = None
        self.cur = None
        self.next = None
        self.parent = parent # Added from level.py in classic for RANDOM Generator
        self.data = data

The only things I added to this list of __init__ was self.parent and self.data which I took from classic.py

self.fname was always fname and None

It's got to be something to do with the way the random code reads the fname, or provides it... I don't know...
Re: From the never-ending pool of Eckels' inane programming questions, comes another one... :: May 12, 2007 @ 7:17am
Ensign philhassey
Joined: Nov 30, 2006
Posts: 678
Location: Zarcon
eckels -

BTW - log.txt is now saved into the data folder - it contains the traceback error you're getting.  Maybe post the last few lines of that - sometimes that can be helpful.

Also - I don't think you need to add the parent and fname variables into the class just because classic had them.  You should be able to copy in the generate function more or less ...

At some point I should expose the Galcon function that auto-moves planets away from each-other.  (So that if yours are too close they will be spaced nicely.)

- Phil
Re: From the never-ending pool of Eckels' inane programming questions, comes another one... :: May 12, 2007 @ 7:22am
Ensign eckels
Joined: Mar 4, 2007
Posts: 200
Traceback (most recent call last):
  File "mymods.pyc", line 354, in fnc
  File "mymods.pyc", line 491, in event
  File "mymods.pyc", line 455, in do_exec
  File "safe.pyc", line 128, in safe_exec
  File "safe.pyc", line 119, in safe_run
  File "", line 1, in ?
  File "mymods.pyc", line 559, in event
  File "mods/mapedit/dialog.py", line 56, in event
  File "mods/mapedit/dialog.py", line 174, in return_
  File "mods/mapedit/edit.py", line 266, in save
  File "mods/mapedit/edit.py", line 288, in do_save
  File "mymods.pyc", line 289, in file_check_name
TypeError: expected string or buffer
['exec: g.event(e)']
Re: From the never-ending pool of Eckels' inane programming questions, comes another one... :: May 12, 2007 @ 7:23am
Ensign eckels
Joined: Mar 4, 2007
Posts: 200
this is with that block of code commented out, so that the random function works, just the load and the save functions are not. This, as you can see from the message, is what happened when i tried to save.
Re: From the never-ending pool of Eckels' inane programming questions, comes another one... :: May 12, 2007 @ 4:42pm
Ensign thirdparty
Joined: Dec 20, 2006
Posts: 279
Location: Eastern U.S.A.
Try making fname default to '' instead of None.  I don't imagine that it matters, but...

You must sign in to post.

Galcon   Watermelons   Dynamite   The Hairy Chestival
All content of imitation pickles (c) 1999-2008 - Phil Hassey  "we care"