FIFE forums

Please login or register.

Login with username, password and session length
Advanced search  

News:

FIFE 0.4.0 has been released on 15th of January, 2017!

Pages: [1] 2 3

Author Topic: Jim's problems  (Read 8514 times)

Jim

  • Newbie
  • Posts: 24
    • View Profile
Jim's problems
« on: July 01, 2013, 10:56:33 am »

Hi, as a complete beginner I thought I'd start out with a simple little task: incorporating the actions of the fiferpg demo into a context menu. I managed to make almost everything work by just following the way they did it in the rio de hola demo and making some adjustments here and there, but now I'm stuck at the very end: when I try to map the widgets to the corresponding events, it just ends up as the character executing the "Look" action every right click and the "instancemenu" widget not doing anything anymore. It works fine when I map something other than the fiferpg actions, but when I have:

        self.instancemenu.mapEvents({
            'moveButton' : self.onMoveButtonPress(player, entity, actions),
            'readButton' : self.onReadButtonPress(player, entity, actions),
            'inspectButton' : self.onInspectButtonPress(player, entity, actions),
        })

corresponding to, e.g.:

    def onMoveButtonPress(self, player, entity, actions):
        self.hide_instancemenu()
        fifeagent.approach_and_execute(player, entity,
            callback=lambda:
                actions["MoveAgent"].execute()
        )

The problem occurs. Does anybody have a clue what I'm doing wrong? I put the updated fiferpg demo in a rar file here by the way.
« Last Edit: July 02, 2013, 06:39:08 pm by Jim »
Logged

ChrisOelmueller

  • Newbie
  • Posts: 15
    • View Profile
Re: Widgets problem
« Reply #1 on: July 01, 2013, 12:43:26 pm »

Hi Jim!

From what you describe, it sounds like one of the pitfalls that manages to catch not only beginners - it's certainly not as intuitive as it should be.
If you're familiar with the concept of "callbacks", in short mapEvents expects those as arguments.

Right now instead of passing the function itself that will be triggered on certain actions, you pass the function call. This means that whenever the mapEvents line is called, all three of those will be executed - and nothing is gonna happen when you expect it after that.

You can either use the Callback classes provided by pychan or fence the function behind `lambda` like this:
Code: [Select]
   self.instancemenu.mapEvents({
            'moveButton': lambda: self.onMoveButtonPress(player, entity, actions),
            'readButton': lambda: self.onReadButtonPress(player, entity, actions),
            'inspectButton': lambda: self.onInspectButtonPress(player, entity, actions),
        })

Hope this helps, if anything was unclear, just mention it :)
Logged

Jim

  • Newbie
  • Posts: 24
    • View Profile
Re: A small issue with pychan
« Reply #2 on: July 02, 2013, 05:07:55 am »

Works perfectly with the lambdas added, thanks! Yeah, callbacks were still a bit of an unknown to me; for instance, I did some reading up on lambda functions earlier and I never really a 100% got the point behind it, but I think I do now because of your explanation, so thanks again!
Logged

Jim

  • Newbie
  • Posts: 24
    • View Profile
Re: Jim's problems
« Reply #3 on: July 02, 2013, 06:49:15 pm »

First off, sorry I'm putting all these undoubtedly stupid questions in the wrong forum, but I figured I might as well stick with this thread and not clutter up everything.

So, I added all the other default actions to the context screen in the fiferpg demo and all of them (close, lock, etc.) work very nicely, except for the pick up action. Even when I give the player entity some free slots for the item (that is, the gold stack) to go in, it returns a KeyError. Here's the report: 

Traceback (most recent call last):
  File "C:\Program Files (x86)\FIFE\demos\fiferpg demo\run.py", line 100, in <module>
    main()
  File "C:\Program Files (x86)\FIFE\demos\fiferpg demo\run.py", line 85, in main
    app.run()
  File "C:\Python27\lib\site-packages\fife\extensions\basicapplication.py", line 197, in run
    retval = self.mainLoop()
  File "C:\Python27\lib\site-packages\fife\extensions\basicapplication.py", line 222, in mainLoop
    self._pump()
  File "C:\Python27\lib\site-packages\bGrease\grease_fife\mode.py", line 54, in _pump
    self.pump(delta_time)
  File "C:\Python27\lib\site-packages\fife_rpg\rpg_application.py", line 826, in pump
    self.check_agent_changes()
  File "C:\Python27\lib\site-packages\fife_rpg\rpg_application.py", line 813, in check_agent_changes
    game_map = self.maps[agent.map]
KeyError: ''

I don't get it. This means the game is looking in a dictionary of maps and can't find " " (or, a nameless map) right? But why would agent.map be blank? Might be that I'm completely on the wrong track of course and am completely missing the point of what a KeyError is.

edit:

I'm guessing I need to add some more information to the function executing the action? Now it's just

    def onPickUpButtonPress(self, player, entity, actions):
        self.hide_instancemenu()
        fifeagent.approach_and_execute(player, entity,
            callback=lambda:
                     actions["PickUp"].execute()
        )

One thing that I find weird about the pickup action is that it has a "menu text" added of its own. Of course I supply that myself already, and while I'm fairly sure it's not what's causing the problem, it might have some role to play.
« Last Edit: July 02, 2013, 07:40:01 pm by Jim »
Logged

Beliar

  • Newbie
  • Posts: 25
    • View Profile
Re: Jim's problems
« Reply #4 on: July 02, 2013, 10:39:52 pm »

Hi Jim,

i think I see the problem, but its with FIFErpg, namely the "remove_entity" method of the map. I will look into how to fix it in the evening today (Central European Time).
Logged

prock

  • Developer
  • Full Member
  • *
  • Posts: 236
    • View Profile
Re: Jim's problems
« Reply #5 on: July 03, 2013, 07:26:36 am »

Hi Jim,

No worries about where you are posting your questions.  Sounds like you uncovered a bug with FIFErpg.  Beliar is the creator of FIFErpg so you are in good hands!
Logged

Beliar

  • Newbie
  • Posts: 25
    • View Profile
Re: Jim's problems
« Reply #6 on: July 03, 2013, 11:41:06 am »

Hi Jim,

I just pushed a commit that should fix the error you got. Please update to the latest git version and try again.
Logged

ChrisOelmueller

  • Newbie
  • Posts: 15
    • View Profile
Re: Jim's problems
« Reply #7 on: July 03, 2013, 12:38:30 pm »

Unrelated: instead of
Code: [Select]
callback=lambda: actions["PickUp"].execute()you can just use this (without the parens):
Code: [Select]
callback=actions["PickUp"].executelambda is only necessary if you want to pass certain arguments as well, and don't want to use either functools.partial or the callback classes.
Logged

Jim

  • Newbie
  • Posts: 24
    • View Profile
Re: Jim's problems
« Reply #8 on: July 03, 2013, 12:50:39 pm »

Works perfectly now, thanks!

In the meantime I have another problem which I now also think might be a bug (though I'm probably just doing something wrong). I was beginning to try some basic things with the dialogue controller in order to eventually add the example dialogue to the demo and this kept popping up:

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\fife\extensions\fife_timer.py", line 125, in updateEvent
    self._callback()
  File "C:\Python27\lib\site-packages\fife\extensions\pychan\tools.py", line 83, in real_callback
    callback(*args,**kwargs)
  File "C:\Python27\lib\site-packages\fife\extensions\pychan\events.py", line 164, in delayed_f
    f( event )
  File "C:\Python27\lib\site-packages\fife\extensions\pychan\events.py", line 327, in captured_f
    tools.applyOnlySuitable(self_ref().callbacks[group_name][event_name],event=event,widget=self_ref().widget_ref())
  File "C:\Python27\lib\site-packages\fife\extensions\pychan\tools.py", line 60, in applyOnlySuitable
    return func(*args,**kwargs)
  File "C:\Program Files (x86)\FIFE\demos\fiferpg demo\demo_game_scene.py", line 101, in <lambda>
    'talkButton' : lambda: self.onTalkButtonPress(player, entity),
  File "C:\Program Files (x86)\FIFE\demos\fiferpg demo\demo_game_scene.py", line 167, in onTalkButtonPress
    dlg = DialogueController(world, application, "dialogue/example.yaml")
  File "C:\Python27\lib\site-packages\fife_rpg\dialogue.py", line 223, in __init__
    self.dialogue = Dialogue(self.application.world, dialogue)
  File "C:\Python27\lib\site-packages\fife_rpg\dialogue.py", line 81, in __init__
    self.create_sections(sections_data)
  File "C:\Python27\lib\site-packages\fife_rpg\dialogue.py", line 183, in create_sections
    section = self.create_section(section_data)
  File "C:\Python27\lib\site-packages\fife_rpg\dialogue.py", line 172, in create_section
    section.text = _(section.text).format(**variables)
  File "C:\Python27\lib\site-packages\bGrease\entity.py", line 90, in __getattr__
    component = getattr(self.world.components, name)
AttributeError: 'ComponentParts' object has no attribute 'description'

upon pressing the talk button in the context menu like so:

    def onTalkButtonPress(self):         
        application = self.gamecontroller.application
        world = application.world
        dlg = DialogueController(world, application, "dialogue/example.yaml")
        dlg.select_response("no_introduce")
        print dlg.current_section.text
« Last Edit: July 03, 2013, 12:52:41 pm by Jim »
Logged

Beliar

  • Newbie
  • Posts: 25
    • View Profile
Re: Jim's problems
« Reply #9 on: July 03, 2013, 01:16:06 pm »

Ah, yeah, I just noticed that I haven't kept the demo in the repository up-to date as I didn't really liked it the way its anyway. Its stull using old names for component fields, here is the updated dialogue file:

Code: [Select]
# This is an example dialogue file

Greetings:
 
  - talker: David
    text: Hey, I've seen you before, haven't I?
    conditions:
      - Type: Knows
        Args: [David, PlayerCharacter]
    responses:
      - "yes"
      - yes_bye
         
  - talker: David
    text: Hi, I don't know you, do I?
    conditions:
      - Type: Not_Knows
        Args: [David, PlayerCharacter]
    responses:
      - no_introduce
      - no_bye

Sections:
  no_introduce:
    talker: PlayerCharacter
    text: No. I am {DialogueTalker.Description.view_name}
    commands:
        - Name: AddKnowledge
          Args: [David, PlayerCharacter]
    responses:
      - introduce_reply
  no_bye:
    talker: PlayerCharacter
    text: No, and I don't want to change that.
  "yes":
    talker: PlayerCharacter
    text: Yes, I am {DialogueTalker.Description.view_name}. Remember?
    responses:
      - yes_reply
  yes_bye:
     talker: PlayerCharacter
     text: Yes, but I am in a hurry. Bye.
  introduce_reply:
    talker: David
    text: Nice to meet you, my name is {DialogueTalker.Description.real_name}
    commands:
      - Name: SetComponentValue
        Args: [David, Description, view_name, "{DialogueTalker.Description.real_name}"]
      - Name: AddKnowledge
        Args: [PlayerCharacter, David]
  yes_reply:
    talker: David
    text: Ah, right.
Logged

Jim

  • Newbie
  • Posts: 24
    • View Profile
Re: Jim's problems
« Reply #10 on: July 03, 2013, 01:38:18 pm »

Thanks! Yeah, I already got the impression that the demo was little more than a placeholder (especially with the weird language changes you threw in the mix ;D). I even had doubts I had properly installed the thing because of all the omissions. Would you be okay with me putting up an "updated" version of the demo for download for beginners like myself? That is, until you have the type of demo you'd like to see yourself of course.
Logged

Beliar

  • Newbie
  • Posts: 25
    • View Profile
Re: Jim's problems
« Reply #11 on: July 03, 2013, 01:42:10 pm »

I won't mind if you do that. The "Demo" is mostly used by me as a tesbed for new functions, so thats why it may seem weird, and why I haven't pushed the local changes to the repo.
« Last Edit: July 03, 2013, 01:44:10 pm by Beliar »
Logged

Jim

  • Newbie
  • Posts: 24
    • View Profile
Re: Jim's problems
« Reply #12 on: July 04, 2013, 07:33:36 pm »

Thanks again for all the help, but I have yet another problem. I've been trying a million different things to get an _init_ function working for the (fiferpg demo's) listener, but every time I get this error:

Traceback (most recent call last):
  File "C:\Program Files (x86)\FIFE\demos\fiferpg demo\run.py", line 266, in <module>
    main()
  File "C:\Program Files (x86)\FIFE\demos\fiferpg demo\run.py", line 250, in main
    app.push_mode(controller)
  File "C:\Python27\lib\site-packages\bGrease\mode.py", line 93, in push_mode
    self.activate_mode(mode)
  File "C:\Python27\lib\site-packages\bGrease\mode.py", line 74, in activate_mode
    mode.activate(self)
  File "C:\Python27\lib\site-packages\bGrease\mode.py", line 162, in activate
    self.on_activate()
  File "C:\Python27\lib\site-packages\fife_rpg\game_scene.py", line 228, in on_activate
    self.listener.activate()
  File "C:\Python27\lib\site-packages\fife_rpg\game_scene.py", line 120, in activate
    self.eventmanager.addMouseListener(self)
  File "C:\Python27\lib\site-packages\fife\fife.py", line 2842, in <lambda>
    __getattr__ = lambda self, name: _swig_getattr(self, IMouseListener, name)
  File "C:\Python27\lib\site-packages\fife\fife.py", line 54, in _swig_getattr
    raise AttributeError(name)
AttributeError: eventmanager

Currently I'm trying this:

class DemoListener(GameSceneListener):
       
    def __init__(self, engine, gamecontroller=None):
        self.engine = engine
        self.gamecontroller = gamecontroller

I checked with other examples and the core scripts and I assumed this should work. Is there something I'm doing wrong?
« Last Edit: July 04, 2013, 07:53:54 pm by Jim »
Logged

Beliar

  • Newbie
  • Posts: 25
    • View Profile
Re: Jim's problems
« Reply #13 on: July 04, 2013, 10:43:39 pm »

Hi Jim,

the problem is, that the init method of the GameSceneListener class is not called. That method is setting needed method variables and other things.

You can do that by writing:

Code: [Select]
GameSceneListener.__init__(self, engine, gamecontroller)
With that you also don't need to set the engine and gamecontroller yourself.
Logged

Jim

  • Newbie
  • Posts: 24
    • View Profile
Re: Jim's problems
« Reply #14 on: July 05, 2013, 04:35:54 am »

Thanks! I really should've noticed that from the other examples, sorry.
Logged
Pages: [1] 2 3