Author Topic: libtcod + python sys check for event error, make no sense!!  (Read 6289 times)

purpherb

  • Newcomer
  • Posts: 1
  • Karma: +0/-0
    • View Profile
libtcod + python sys check for event error, make no sense!!
« on: February 11, 2013, 06:49:03 AM »
So I am working on a command menu for this RL I am developing, and I am running into an error that makes no sense at all to me. I am a beginner btw.

So in the menu function I test the key to see which command to call after which a function is called in which the player clickson a tile to set a destination. I am literally doing the exact same thing for each key, typed below...
if key == 'a':
   libtcod.console_flush()
   person = choose_ally()          <--------------------- WORKS FINE!!
   person.ai.get_destination()

elif key == 'b':
   libtcod.console_flush()
   person = choose_ally()        <------------------ ERROR?!?!  >:(
   person.ai.get_destination
   person.hold = True
elif key == 'c':
   libtcod.console_flush()
   person = choose_ally           <--------------- ERROR?!!   >:(   >:(
   person.hold = None
If I press a than everything works fine. But if I press b or c and than choose any player than I get:

    return _lib.TCOD_sys_check_for_event(c_int(mask),byref(k),byref(m))
TypeError: byref() argument must be a ctypes instance, not 'str'

The choose ally function is written below, all it does it either return ally or ally2, both of which are Objects with the same BasicAlly ai.

def choose_ally():
   
   options = [ally.name, ally2.name]
   header = ''
   key = menu(header, options, 20)
         
   char = chr(key + ord('a'))
   
   if char == 'a':
      return ally
   elif char == 'b':
      return ally2



Please someone help me out,I have been really getting into developing and I think I have a pretty good idea for a RL. I will attach the full code to this in the case that someone has some time to figure out whats going on. I followed the libtcod python tutorial and than taught myself how to add allys that the player will semi-command so don;t tear my coding apart or steal my ideas (or at least the first small part of the idea I am trying to implement)  ;D

purpherb

UPDATE: file is too big to upload but i can send it to someone somehow if anyone is willing to give me some help!

requerent

  • Rogueliker
  • ***
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: libtcod + python sys check for event error, make no sense!!
« Reply #1 on: February 13, 2013, 01:05:50 AM »
Which Python IDE are you using? I recommend PTVS (Python Tools for Visual Studio- you can set it up for free w/the integrated shell). PTVS uses intellisense to provide awesome context assistance and error checking.


You've got some basic syntactical problems. Python's Duck-typing doesn't know that you're calling a function if you don't include the parenthesis.

IE.
person = choose_ally

should be:
person = choose_ally()

Your code should probably look like this.

Code: [Select]
if key == 'a':
   libtcod.console_flush()
   person = choose_ally()
   person.ai.get_destination()

elif key == 'b':
   libtcod.console_flush()
   person = choose_ally()
   person.ai.get_destination()
   person.hold = True

elif key == 'c':
   libtcod.console_flush()
   person = choose_ally()
   person.hold = None