General Category > Game creators corner

Jim's problems

(1/8) > >>

Jim:
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.

ChrisOelmueller:
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: ---   self.instancemenu.mapEvents({
            'moveButton': lambda: self.onMoveButtonPress(player, entity, actions),
            'readButton': lambda: self.onReadButtonPress(player, entity, actions),
            'inspectButton': lambda: self.onInspectButtonPress(player, entity, actions),
        })
--- End code ---

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

Jim:
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!

Jim:
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.

Beliar:
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).

Navigation

[0] Message Index

[#] Next page

Go to full version