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
<py> dodgeball

 
Post new topic   Reply to topic Printable version
 View previous topic  A little bit of help Post :: Post Hs_ufo  View next topic  
Author Message
xsp0rtsfanx
Seasoned Helper


Age:30
Gender:Gender:Male
Joined: Dec 27 2004
Posts: 168
Location: California
Offline

PostPosted: Sat Mar 18, 2006 6:15 pm    Post subject: <py> dodgeball Reply to topic Reply with quote

Ok so this is my first attempt at a module.. and I know there is a syntax error and what line but the error is not marking the code itself.. but the whitespace after the code. It's attached. Line 25 if you people could help me get it working perfectly I'd appreciate it.


PS. there are no commands due to the fact I was making this module for Hockey Zone and there are modules made to set commands up for the module without putting them in the actual code.


Last edited by xsp0rtsfanx on Sun Mar 19, 2006 1:29 am, edited 2 times in total
Back to top
View users profile Send private message Add User to Ignore List MSN Messenger
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Sat Mar 18, 2006 6:29 pm    Post subject: Reply to topic Reply with quote

I don't know python, but from the syntax I see, it looks like inconsistent use of the colon after an if.
_________________
4,691 irradiated haggis!
Back to top
View users profile Send private message Add User to Ignore List
xsp0rtsfanx
Seasoned Helper


Age:30
Gender:Gender:Male
Joined: Dec 27 2004
Posts: 168
Location: California
Offline

PostPosted: Sat Mar 18, 2006 6:46 pm    Post subject: Reply to topic Reply with quote

Oh shit I completely didn't notice that. That's probably it.
Back to top
View users profile Send private message Add User to Ignore List MSN Messenger
xsp0rtsfanx
Seasoned Helper


Age:30
Gender:Gender:Male
Joined: Dec 27 2004
Posts: 168
Location: California
Offline

PostPosted: Sun Mar 19, 2006 1:28 am    Post subject: Reply to topic Reply with quote

Update: I figured out my problems from the first post.. I just can't get the the attach to work and I can't figure out the code for detach :/



dodgeball.py - 1.08 KB
File downloaded or viewed 50 time(s)
Back to top
View users profile Send private message Add User to Ignore List MSN Messenger
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Sun Mar 19, 2006 8:51 am    Post subject: Reply to topic Reply with quote

There's some stuff here Wiki:Writing Modules In Python about attaching modules and other things you can do in python.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
xsp0rtsfanx
Seasoned Helper


Age:30
Gender:Gender:Male
Joined: Dec 27 2004
Posts: 168
Location: California
Offline

PostPosted: Sun Mar 19, 2006 10:31 pm    Post subject: Reply to topic Reply with quote

I've already been to the site but I'm getting errors with my attach and I'm not sure what to put in the detach. Would the detach have the callbacks and have it = None?
Back to top
View users profile Send private message Add User to Ignore List MSN Messenger
Chambahs
Power attack
Power attack


Joined: Jun 19 2005
Posts: 820
Offline

PostPosted: Sun Mar 19, 2006 11:14 pm    Post subject: Reply to topic Reply with quote

def mm_attach(arena):
arena.wpn_cb1 = reg_callback(CB_KILL, kill, arena)
#arena.wpn_oldfm = get_interface(I_FREQMAN, arena)
#arena.wpn_myfm = reg_interface(I_FREQMAN, myfm, arena)

# make one timer only
if wpn_bigref[0] == None:
wpn_bigref[0] = make_region_timer(500, 100)
wpn_bigref_count[0] += 1

def mm_detach(arena):
for attr in ['cb1', 'oldfm', 'myfm']:
try: delattr(arena, 'wpn_' + attr)
except: pass

wpn_bigref_count[0] -= 1
if wpn_bigref_count[0] <= 0:
wpn_bigref[0] = None

Theres some code from a module of UT, showing how the attach and detach looks on some of our modules. Also, I am rewritting your whole module, but it turns up that I need some help as well. Ill try to finish it by tomarrow. (Monday)
Back to top
View users profile Send private message Add User to Ignore List
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Mon Mar 20, 2006 6:04 am    Post subject: Reply to topic Reply with quote

In Chambahs example ignore the stuff about the region timer (that's there because there is no region callback for py). To see another example of attach/detach with proper indenting look at the py modules that come with asss. Such as bin/fg_wz.py.

Another thing is you should be prefixing your per arena/player data with the name of your module to prevent clashes with other modules. For example: arena.db_timer where db_ means dodgeball.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
Chambahs
Power attack
Power attack


Joined: Jun 19 2005
Posts: 820
Offline

PostPosted: Mon Mar 20, 2006 1:48 pm    Post subject: Reply to topic Reply with quote

Was going to finish the dodgeball module i was working on, but it seems that smong beat me to the punch, and his is better. So check his out to see what can be done to make yours better.
Back to top
View users profile Send private message Add User to Ignore List
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Mon Mar 20, 2006 5:30 pm    Post subject: Reply to topic Reply with quote

Well I was never planning on releasing it since I want to see other people working on asss. If anyone still wants to see it they can pm me.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
xsp0rtsfanx
Seasoned Helper


Age:30
Gender:Gender:Male
Joined: Dec 27 2004
Posts: 168
Location: California
Offline

PostPosted: Tue Mar 21, 2006 6:13 pm    Post subject: Reply to topic Reply with quote

Ok so I have the code working but it wont attach (no errors it just wont attach). Help please



dodgeball.py - 1.15 KB
File downloaded or viewed 24 time(s)
Back to top
View users profile Send private message Add User to Ignore List MSN Messenger
Chambahs
Power attack
Power attack


Joined: Jun 19 2005
Posts: 820
Offline

PostPosted: Tue Mar 21, 2006 11:45 pm    Post subject: Reply to topic Reply with quote

Hmm, i dont think that attach and detach code should be in there.
Back to top
View users profile Send private message Add User to Ignore List
xsp0rtsfanx
Seasoned Helper


Age:30
Gender:Gender:Male
Joined: Dec 27 2004
Posts: 168
Location: California
Offline

PostPosted: Tue Mar 21, 2006 11:46 pm    Post subject: Reply to topic Reply with quote

what do you mean? how else would i load the module tongue.gif
Back to top
View users profile Send private message Add User to Ignore List MSN Messenger
Chambahs
Power attack
Power attack


Joined: Jun 19 2005
Posts: 820
Offline

PostPosted: Tue Mar 21, 2006 11:57 pm    Post subject: Reply to topic Reply with quote

About the detach and attach code, when I started python, I never used it. And when I did decide to use it, I always use this:

def mm_attach(arena):
# do stuff with arena
def mm_detach(arena):
# undo stuff

In my opinion I believe that the attach and detach code is specifically there so if you have settings that change or things you define, you put them in there. Let me give you an example of how -I- use it.


def blah(arena):
this code will make settings so 2 repels are max
this code has a callback in it

attach code:
repels = max when the code is attached
calls a callback when it attaches

detach code:
repels = back to normal settings because its detached
callback isnt called when detached


That was lamens terms. Now I will show you actual code that shows you what I meant.


def mm_attach(arena):
arena.leader_killcb = reg_callback(CB_KILL, kill, arena)
arena.leader_cmd1 = add_command("startgame", c_start_game, arena)
arena.leader_cmd2 = add_command("stopgame", do_game_over, arena)

def mm_detach(arena):
arena.leader_killcb = None
arena.leader_cmd1 = None
arena.leader_cmd2 = None


Still keep in mind im no expert, but I should be on the right track.
Back to top
View users profile Send private message Add User to Ignore List
Chambahs
Power attack
Power attack


Joined: Jun 19 2005
Posts: 820
Offline

PostPosted: Wed Mar 22, 2006 12:00 am    Post subject: Reply to topic Reply with quote

Also, sorry for the double post. But here is an attempt I made on the dodgeball module. Ive never done anything with balls before, so I was kind of shooting in the dark. Its not finished and I doubt all of it is good coding but meh, just showing ya what I tried.



Attempt #1

db.py - 1.67 KB
File downloaded or viewed 39 time(s)
Back to top
View users profile Send private message Add User to Ignore List
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Wed Mar 22, 2006 10:54 am    Post subject: Reply to topic Reply with quote

xsp0rtsfanx wrote:
Ok so I have the code working but it wont attach (no errors it just wont attach). Help please
You shouldn't have to use a try/except block in mm_attach.

There's a lot of things wrong in your module. I'll start from the top:
  • bd = balldata() - There is no balldata function defined any where.
  • db_timer = set_timer(timer, 200); - the variable db_timer should most likely be in the arena data. You don't need a semicolon on the end of the line.
  • if bd.state == CB_BALLFIRE:You've already got
    arena.db_gameoverref = reg_callback(CB_BALLFIRE, gameover, arena)
    so you know this function only gets called on the ball fired event. Also the variable bd didn't exist before this line.
  • db_timer.start() - thats not how you start timers, see the wiki.
  • if a.playerover <= db_timer:a.playerover never existed until this point. You can't compare it with a timer either, since timer variables in py are references and don't have any useful value.
  • chat.SendArenaMessage(arena, "p could not dodge a wrench or a ball and is OUT!") - Read some py tutorials and learn about string formatting. Heres how it should be done chat.SendArenaMessage(arena, "%s could not dodge a wrench or a ball and is OUT!" % p.name)
  • if count_playing(arena) == 1: - where is function count_playing defined? Also what happens if there are 0 people playing? (Unexpected maybe, but possible).
  • for_each_player(count_playing) - again no function count_playing defined. Maybe you want something like:
    Code: Show/Hide

    def count_playing(arena):
      # use a 1 element list since apparently everything else is immutable inside nested functions.
      playing = [ 0 ]
      def cb_count(p):
        if p.arena == arena and p.ship != SHIP_SPEC:
          playing[0] += 1
      for_each_player(cb_count)
      return playing[0]

  • chat.SendArenaMessage(arena, for_each_player, " is the winner!") - string format again
Back to top
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> ASSS Custom Projects 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: 195 page(s) served in previous 5 minutes.

phpBB Created this page in 0.149346 seconds : 42 queries executed (61.2%): GZIP compression disabled