General Category > Game creators corner

Jim's problems

(1/8) > >>

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:

            '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):
        fifeagent.approach_and_execute(player, entity,

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.

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

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!

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\", line 100, in <module>
  File "C:\Program Files (x86)\FIFE\demos\fiferpg demo\", line 85, in main
  File "C:\Python27\lib\site-packages\fife\extensions\", line 197, in run
    retval = self.mainLoop()
  File "C:\Python27\lib\site-packages\fife\extensions\", line 222, in mainLoop
  File "C:\Python27\lib\site-packages\bGrease\grease_fife\", line 54, in _pump
  File "C:\Python27\lib\site-packages\fife_rpg\", line 826, in pump
  File "C:\Python27\lib\site-packages\fife_rpg\", line 813, in check_agent_changes
    game_map = self.maps[]
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 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.


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):
        fifeagent.approach_and_execute(player, entity,

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.

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


[0] Message Index

[#] Next page

Go to full version