Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
python region

 
Post new topic   Reply to topic Printable version
 View previous topic  ASSS Errors Post :: Post Difference between as3 windows/linux m...  View next topic  
Author Message
Plareplane
Guest


Offline

PostPosted: Sun Jul 09, 2006 12:21 pm    Post subject: python region Reply to topic Reply with quote

How do I read the region chunks in python? The following does not do what I'd expect it to do:
Code: Show/Hide

# demo
from asss import *

# magic numbers
rTIL = 0x4C495472
rNAM = 0x4D414E72
rNAW = 0x57414E72
rBSE = 0x45534272
rAWP = 0x50574172

chat = get_interface(I_CHAT)
mapd = get_interface(I_MAPDATA)
def mm_attach(arena):
   arena.wbgoal = mapd.FindRegionByName(arena, "wbgoal")
   # i should have all of these
   arena.rAWP = mapd.RegionChunk(arena.wbgoal, rAWP)
   arena.rBSE = mapd.RegionChunk(arena.wbgoal, rBSE)
   arena.rNAM = mapd.RegionChunk(arena.wbgoal, rNAM)
   arena.rTIL = mapd.RegionChunk(arena.wbgoal, rTIL)
   # i shouldn't have any rNAW
   arena.rNAW = mapd.RegionChunk(arena.wbgoal, rNAW)
   # let's see what we get
   chat.SendArenaMessage(arena, "rAWP" + str(type(arena.rAWP)))
   chat.SendArenaMessage(arena, "rBSE" + str(type(arena.rBSE)))
   chat.SendArenaMessage(arena, "rNAM" + str(type(arena.rNAM)))
   chat.SendArenaMessage(arena, "rTIL" + str(type(arena.rTIL)))
   chat.SendArenaMessage(arena, "rNAW" + str(type(arena.rNAW)))


Here's the output:
Code: Show/Hide

         Plareplane> ?|attmod -d demo|rmmod demo|insmod <py> demo|attmod demo
Module demo detached.
Module demo unloaded successfully
Module <py> demo loaded successfully
rAWP<type 'str'>
rBSE<type 'str'>
rNAM<type 'NoneType'>
rTIL<type 'NoneType'>
rNAW<type 'NoneType'>
Module demo attached.
         Plareplane> ?py print(a.rAWP)
E <pymod> error in command handler for 'py'
         Plareplane> ?py print(a.rBSE)
         Plareplane> ?py print(a.rNAM)
None
         Plareplane> ?py print(a.rTIL)
None
         Plareplane> ?py print(a.rNAW)
None


The error in print(a.rAWP) is:
Code: Show/Hide

Traceback (most recent call last):
  File "/home/plareplane/software/asss/bin/exec.py", line 46, in c_py
    chat.SendMessage(player, l)
TypeError: argument 2 must be string without null bytes, not str


Shouldn't I be getting some sort of tuple for rAWP, rNAM, and rTIL? (Or a list of bytes would be nice.) Why do I get None for rNAM and rTIL?

Also, what is required to make a callback in c available in python? I see that the available python callbacks have a /* pycb ... */ in the c code, but I'm not sure what else there is to it. Specifically, I'd like to use the CB_REGION callback, but the guide on the wiki seems to say that it is not currently available.
Back to top
Plareplane
Guest


Offline

PostPosted: Sun Jul 09, 2006 12:59 pm    Post subject: Reply to topic Reply with quote

Also, I only started learning python a couple days ago from reading the python module guide coupled with occasional glances at the api on python.org, so if something is outrageously bad in the above learning example, let me know.
Back to top
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Sun Jul 09, 2006 2:00 pm    Post subject: Reply to topic Reply with quote

You should probably check if arena.wbgoal is None before you try to use it.

Why the other stuff doesn't work I don't know. You can edit game.h line 93 if you want to play with CB_REGION, although I don't know if that will actually work since it must be disabled for a reason (increased server load maybe).
Back to top
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
Plareplane
Guest


Offline

PostPosted: Sun Jul 09, 2006 2:21 pm    Post subject: Reply to topic Reply with quote

I didn't bother checking wbgoal because I just editted a map specifically with a region named wbgoal just to test how things work. Can FindRegionByName return None in this case?
Back to top
Grelminar
Creator of Asss


Joined: Feb 26 2003
Posts: 378
Offline

PostPosted: Sun Jul 09, 2006 3:59 pm    Post subject: Reply to topic Reply with quote

The type error is pretty clear: your chunk has nul bytes in it. Strings are the most efficient way to pass around binary data in python, and so RegionChunk returns strings (or None, if the chunk isn't there). Chunks can contain binary data, but strings used for messages can't (actually, that's the first time I heard of that restriction, but it makes sense).

Adding a pycb thing for CB_REGION should be enough. I think the reason it's not there is because it gets called synchronously in the unreliable thread, and having a callback do a lot of work there would be bad. Feel free to add it, just be careful about doing stuff that could take too long.
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Sun Jul 09, 2006 6:42 pm    Post subject: Reply to topic Reply with quote

Code: Show/Hide
   int (*RegionChunk)(Region *rgn, u32 ctype, const void **datap, int *sizep);
   /* pyint: region, int, bufp out, int buflen out -> void */
Since it says 'out' twice, why doesn't it return a tuple with 2 elements?
Back to top
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
Grelminar
Creator of Asss


Joined: Feb 26 2003
Posts: 378
Offline

PostPosted: Sun Jul 09, 2006 7:00 pm    Post subject: Reply to topic Reply with quote

Because bufp/buflen parameters are handled specially. I suppose I could change it so the second "out" isn't required, but conceptually, it is an "out" parameter, so it makes sense to have it there.
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website
Plareplane
Guest


Offline

PostPosted: Sun Jul 09, 2006 8:01 pm    Post subject: Reply to topic Reply with quote

Quote:

The type error is pretty clear: your chunk has nul bytes in it. Strings are the most efficient way to pass around binary data in python, and so RegionChunk returns strings (or None, if the chunk isn't there).


Ok, so rAWP, rBSE, and rNAW were exactly what they were expected to be (4 bytes corresponding to a coord, 0 bytes, and None, respectively), but why do I get None for rTIL and rNAM? I thought maybe I got my magic numbers wrong, but I used the same method (writing r??? in hex) for each one, and it clearly worked for rAWP and rBSE.

Quote:

Chunks can contain binary data, but strings used for messages can't (actually, that's the first time I heard of that restriction, but it makes sense).


I'm not sure if I understand exactly what you mean.

As a side note, is the rPYC chunk type implemented?
Back to top
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Sun Jul 09, 2006 8:36 pm    Post subject: Reply to topic Reply with quote

I don't think rPYC is implemented. Although it would be extremely cool if it was. It would save having to make custom region types for things like object toggling, ship changing and prizing.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
Plareplane
Newbie


Joined: Jul 09 2006
Posts: 14
Offline

PostPosted: Mon Jul 10, 2006 3:26 am    Post subject: Reply to topic Reply with quote

Changed a line in src/include/game.h and added a few lines to scripts/pymod-process.py. CB_REGION seems to work now (at least for my simple test of flying over a region and having a module call out the name of the region).



pymod-process.py.diff.txt - 0.49 KB
File downloaded or viewed 14 time(s)

game.h.diff.txt - 0.43 KB
File downloaded or viewed 9 time(s)
Back to top
View users profile Send private message Add User to Ignore List AIM Address MSN Messenger
Plareplane
Newbie


Joined: Jul 09 2006
Posts: 14
Offline

PostPosted: Wed Jul 12, 2006 3:39 am    Post subject: Reply to topic Reply with quote

I don't think too many people will be interested, but I wrote/translated a py version of autowarp. It seems to work after some minutes of testing.



autowarp.py - 0.87 KB
File downloaded or viewed 17 time(s)
Back to top
View users profile Send private message Add User to Ignore List AIM Address MSN Messenger
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Wed Jul 12, 2006 11:01 am    Post subject: Reply to topic Reply with quote

Hmm. When you unpack I think you can do something like this:
Code: Show/Hide
x, y, name = unpack("hh16s", aw)

That would help to make it more readable.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
Plareplane
Newbie


Joined: Jul 09 2006
Posts: 14
Offline

PostPosted: Wed Jul 12, 2006 11:42 am    Post subject: Reply to topic Reply with quote

Newbie pythoner me didn't know that. icon_redface.gif Suggestion taken.

Now, if only I can figure out why RegionChunk still can't find chunk type rNAM and rTIL




autowarp.py - 0.88 KB
File downloaded or viewed 15 time(s)
Back to top
View users profile Send private message Add User to Ignore List AIM Address MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> ASSS Questions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 37 page(s) served in previous 5 minutes.

phpBB Created this page in 0.798735 seconds : 37 queries executed (96.1%): GZIP compression disabled