FIFE forums

General Category => Game creators corner => Topic started by: Jim on July 01, 2013, 10:56:33 am

Title: Jim's problems
Post by: Jim 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 (https://www.box.com/s/h321hj7utxzk0e55glsr) by the way.
Title: Re: Widgets problem
Post by: ChrisOelmueller 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 :)
Title: Re: A small issue with pychan
Post by: Jim 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!
Title: Re: Jim's problems
Post by: Jim 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.
Title: Re: Jim's problems
Post by: Beliar 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).
Title: Re: Jim's problems
Post by: prock 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!
Title: Re: Jim's problems
Post by: Beliar 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.
Title: Re: Jim's problems
Post by: ChrisOelmueller 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.
Title: Re: Jim's problems
Post by: Jim 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
Title: Re: Jim's problems
Post by: Beliar 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.
Title: Re: Jim's problems
Post by: Jim 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.
Title: Re: Jim's problems
Post by: Beliar 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.
Title: Re: Jim's problems
Post by: Jim 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?
Title: Re: Jim's problems
Post by: Beliar 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.
Title: Re: Jim's problems
Post by: Jim on July 05, 2013, 04:35:54 am
Thanks! I really should've noticed that from the other examples, sorry.
Title: Re: Jim's problems
Post by: Jim on July 08, 2013, 08:15:52 am
Well, I've made my first version of the amazing fiferpg demo, "the enhanced edition" (https://www.box.com/s/h321hj7utxzk0e55glsr). You can now pick up gold, open your inventory and see the gold in it, click on it to remove it from your inventory and open the chest and compare inventories with it in a friendly fashion. You can also have a short dialogue with David, though that's still a bit... odd. There's even a console where the descriptions of the "inspect" action neatly appear. Which brings me to the three things I've really not managed to figure out how to accomplish:

1: I found out how to make a list of labeled inventory items in pychan where if you click on a specific label, it removes it. But as far as I can tell, you can only do this using the generic widget like in the dynamic widgets demo. Because if you don't, then it's impossible to have it tell which label you've clicked (just that you've clicked some label). Now, the problem with this is that I've noticed that you can't carry over variables with this generic widget, i.e. you can do:

item.capture(self.drop) [with "item" being the label, and "drop" being the item removing function]

but you can't do:

item.capture(self.drop(entity)) or item.capture(lambda: self.drop(entity))

and still use the generic widget. While this isn't a problem with, say, dropping an item, it seems to make taking an item from one container to another impossible. Is there maybe another way to tell exactly which label is being "captured"?

2: A more fiferpg specific question: after removing the gold from the inventory I want it to appear on the ground; I'm sure I can create an instance of gold easily, but what I should actually be doing is create a gold entity instead, right? But how would I do that? I know there's a get_or_create_entity function, but that doesn't seem to do anything even when I do something like update_entities after that.

3: Another fiferpg specific question: I have no clue how to make it so that the possible responses of the dialogue appear as the responses themselves, rather than the keys of the dictionary, so in the dialogue I have now, the responses appear as "no_introduce" etc. I probably just don't understand dictionaries well enough, because I assumed the keys would "point" to the text itself, but instead they point to a certain address in the code, which I have no idea how to use.

Again, sorry if one/some/all of these questions is/are really stupid.
Title: Re: Jim's problems
Post by: Beliar on July 08, 2013, 04:18:53 pm
Hi Jim,

for the second question, it should be enough to set the Map and Position fields of the Agent component of the gold entity.

for the third, you should read the Dialogue tutorial (http://fife-rpg.github.io/tutorial/dialogue.html)

For the first you will have to wait for someone who knows more about the widgets than i do.
Title: Re: Jim's problems
Post by: Jim on July 09, 2013, 10:40:52 am
Thanks again! I've already gone over all your tutorials (they're very nice by the way, would be cool if fife had the same type of introductory tutorials), but I'll go over the dialogue one again when I get back from holidays. Like I said, it's probably that I just don't know yet how to handle dictionaries properly; I'll probably just have to go over some general Python tutorials again too.
Title: Re: Jim's problems
Post by: Beliar on July 10, 2013, 10:42:57 am
Hi Jim,

seems like I wrote to fast, the tutorial actually would not help with your problem. The way you iterate over the dictionary will only return the keys of it, not the items, which are dialogue sections. So, yeah, you probably should look at a Tutorial about python dictionaries.

[Edit]
Also:

For your second question, I pushed a commit that fixes a bug where that would have been impossible.
You will have to set the "new_map", "new_position", and "new_layer" fields of the Agent component.
You could just use the "map", "position", and "layer" fields of the Player Agent component for these.
Title: Re: Jim's problems
Post by: Jim on August 14, 2013, 04:44:52 pm
I'm back and ready to be annoying again!

So, two of the three problems I've had still completely elude me. Good news is I finally figured out how to do the fiferpg dialogue thing properly, though I'm admittedly not entirely sure whether it's an unnecessary workaround or not, because I'm still basically just using the keys in the dictionary and not the values. Works fine though, so I'm happy.

The pychan problem is still utterly baffling to me, no matter how many different approaches I try. Maybe I'll just ask it on irc at some point in case nobody responds (unless they're all purposely ignoring me of course). To rephrase the problem a bit: when you populate lists of dialogue options or inventory items or whatever, then you usually need to know which one the player clicked on. For some reason I can't figure out, this is seemingly only possible without carrying over any additional arguments. I.e., to use the way I did the dialogue thing as an example:

        for possible_response in dlg.possible_responses:
            response = pychan.widgets.Label(max_size=(200,1000),wrap_text=True)
            response.text = dlg.dialogue.sections["%s" % possible_response].text
            self.responsesbox.addChild( response )
            response.capture(self.respond)

This works fine, as long as you use a "generic widget" in the called function. But the moment you don't use this generic widget, and try to carry over any information (e.g. use "response.capture(lambda: self.respond(response))" then suddenly the event mapping goes all wrong and pychan can't tell anymore which label in the list you've clicked on (I think it automatically assumes it's the last one). Again, does anyone happen to know how to avoid this?

Quote
For your second question, I pushed a commit that fixes a bug where that would have been impossible.
You will have to set the "new_map", "new_position", and "new_layer" fields of the Agent component.
You could just use the "map", "position", and "layer" fields of the Player Agent component for these.

I still can't get it to work I'm afraid. When I do this (with your commit downloaded of course):

        thing.Agent.new_map = player.Agent.map
        thing.Agent.new_layer = player.Agent.layer
        thing.Agent.new_position = player.Agent.position

Then 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 251, 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 833, in pump self.current_map.update_entitities_agent()
  File "C:\Python27\lib\site-packages\fife_rpg\map.py", line 209, in update_entitities_agent location = fifeagent.behaviour.location
  AttributeError: 'NoneType' object has no attribute 'location'

I tried some (probably stupid) workarounds of forcibly giving the Gold agent a behavior (with the idea of that giving him the error-inducing behavior.location as well), but that just resulted in nothing happening. No clue what's going wrong.


 
Title: Re: Jim's problems
Post by: Beliar on August 15, 2013, 02:54:40 am
Hmm, could you give me the complete code from run.py and demo_game_scene.py?

And to what commit did you update? You need to have at least this one: https://github.com/fife-rpg/fife-rpg/commit/d4d15bf9e107a07b04f42aaf2b77f223a9e8ea39

Although even without that I would not get the error you get, so i'd be best to have the code to check if you try to do things differently than me.
Title: Re: Jim's problems
Post by: Jim on August 15, 2013, 05:41:30 am
Of course! Here it is. (https://app.box.com/s/h321hj7utxzk0e55glsr) These are all the files I've changed/added (plus run.py and actions.py which I didn't change at all). Worked exactly like my own when I overwrote the original fiferpg demo with these files.

And yeah, I just updated that commit (I haven't updated any of the other ones since then).
Title: Re: Jim's problems
Post by: Beliar on August 15, 2013, 06:23:34 am
Hmm, this is really strange. With that code you sent it works without problems here.

I have uploaded a complete working version here: https://dl.dropboxusercontent.com/u/29933429/programming/fiferpg%20demo.7z (May take a few minutes before its available)
Title: Re: Jim's problems
Post by: Jim on August 15, 2013, 08:12:41 am
Hmmm... I must be doing something seriously wrong. I downloaded your version of the demo, which still had the same problem, so I thought I'd better just update to the latest version (downloading the batch, run setup.py). Then I got this error right off the bat:

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 70, in main
    app.switch_map("Level1")
  File "C:\Python27\lib\site-packages\fife_rpg\rpg_application.py", line 450, in switch_map
    callback(old_map, name)
TypeError: on_map_switched() takes exactly 1 argument (3 given)

Then reinstalled, feeling I'd done the exact same thing, and now the error has changed (slightly) to:

Traceback (most recent call last):
  File "C:\Program Files (x86)\FIFE\demos\fiferpg demo1\run.py", line 266, in <module>
    main()
  File "C:\Program Files (x86)\FIFE\demos\fiferpg demo1\run.py", line 70, in main
    app.switch_map("Level1")
  File "C:\Python27\lib\site-packages\fife_rpg\rpg_application.py", line 446, in switch_map
    self.load_map(name)
  File "C:\Python27\lib\site-packages\fife_rpg\rpg_application.py", line 422, in load_map
    game_map = Map(fife_map, name, camera, regions, self)
TypeError: __init__() takes exactly 5 arguments (6 given)


Ugh. I'll just try reinstalling FIFE as a whole in a while (it isn't a problem that I'm using the latest regular FIFE release and not the source, right?).
Title: Re: Jim's problems
Post by: Beliar on August 15, 2013, 08:28:59 am
The first error you are getting is because i made some breaking changes in the last week, on_map_switched now should take two arguments, old_map and new_map, wich are the names of the old and new map. The second one should not happen if FIFErpg is correctly installed as it seems it uses files from two different versions.

And FIFErpg does not work the the current fife from source, only the latest fife release(0.3.4) and the current source of the upcoming release(0.3.5).

[edit]
Also, you would need to change the main function of run.py to this:

Code: [Select]
def main():
    global world
    PrintAction.register()
   
    app = RPGApplication(TDS)
    app.load_components("combined.yaml")
    app.register_components()
    app.load_actions("combined.yaml")
    app.register_actions()
    app.load_systems("combined.yaml")
    app.register_systems()
    app.load_behaviours("combined.yaml")
    app.register_behaviours();
    app.create_world()
    world = app.world
    view = GameSceneView(app)
    controller = DemoController(view, app, outliner=DemoOutliner())
    controller.listener.is_outlined = True
    controller.outliner.outline_ignore.append("PlayerCharacter")
    controller.outliner.outline_data = (173, 255, 47, 2)
    app.load_maps()
    world.read_object_db()
    world.import_agent_objects()
    world.load_and_create_entities()
    app.switch_map("Level1")
   
    script_system = getattr(world.systems, "scripting")
    statistic_system = world.systems.character_statistics
    statistic_system.load_statistics_from_file("statistics.yaml")
    player = app.current_map["PlayerCharacter"]
    player.CharacterStatistics.gender = "male"
    player.CharacterStatistics.primary_stats["ST"] = 75
    player.CharacterStatistics.primary_stats["VT"] = 60
    app.push_mode(controller)
    app.run()
Title: Re: Jim's problems
Post by: Jim on August 15, 2013, 10:06:37 am
Got it to work! Thanks immeasurably for the help and patience. I was such an idiot for forgetting that updating to the latest fiferpg version would completely mess up the outdated demo.

Edit: incidentally, if somebody could also find the patience to help out with the non-fiferpg-related widget problem, then that'd be great as well of course.  ;)

Edit: Ah, think I finally figured it out. I should have gone with the Listbox dealio.
Title: Re: Jim's problems
Post by: Beliar on August 16, 2013, 03:49:23 am
Good that its working for you.

I just noticed that i forgot, that the dialogue conditons work differently now, for the example dialogue replace the file contents with this, if you use the latest fiferpg source:


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

Greetings:
 
  - talker: David
    text: Hey, I've seen you before, haven't I?
    conditions: Agent.knows(entities.David, "PlayerCharacter")
    responses:
      - "yes"
      - yes_bye
         
  - talker: David
    text: Hi, I don't know you, do I?
    conditions: not Agent.knows(entities.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.

I still need to update the tutorials for the changes.
Title: Re: Jim's problems
Post by: Jim on July 05, 2014, 12:46:30 pm
Hey Beliar, thought I'd try and update the demo to 0.2 after almost a year long hiatus, so if you're still up for answering my stupid questions that'd be great!

Code: [Select]
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 70, in main
    app.switch_map("Level1")
  File "C:\Python27\lib\site-packages\fife_rpg\rpg_application.py", line 450, in switch_map
    callback(old_map, name)
TypeError: on_map_switched() takes exactly 1 argument (3 given)

The error you are getting is because i made some breaking changes in the last week, on_map_switched now should take two arguments, old_map and new_map, wich are the names of the old and new map.

This still has me completely stumped. If this is the case, then why is the error:

Code: [Select]
TypeError: on_map_switched() takes exactly 1 argument (3 given)
shouldn't 3 arguments given be the right amount given that:

Code: [Select]
on_map_switched(self, new_map, old_map)
The demo runs fine when I remove the last two arguments required by on_map_switched and the two provided by the callback in switch_map, so I haven't a clue what's going wrong.
Title: Re: Jim's problems
Post by: Beliar on July 06, 2014, 12:44:06 am
Hi, i am not completely sure, but I think the problem was, that fife-rpg passes 2 arguments to the function. But the method expects None (self is automatically passed since its a class method). So the method has to be rewritten to accept the 2 additional arguments.

If that is not working then I need the source code.
Title: Re: Jim's problems
Post by: Jim on July 06, 2014, 04:54:28 am
Sorry, but still can't figure out for the life of me what exactly I'd have to change in the last method to make it work.

Code: (demo's run.py) [Select]

import os
from fife import fife
from fife.extensions.fife_settings import Setting
from fife_rpg import GameSceneView
from fife_rpg import RPGApplication
from fife_rpg.game_scene import SimpleOutliner
from fife_rpg.components import ComponentManager
from fife_rpg.actions import ActionManager
from demo_game_scene import DemoController
from actions import PrintAction

TDS = Setting(app_name="rpg", settings_file="./settings.xml")
world = None
   
def create_entity_dictionary(entity):
    entity_dict = {}
    components_data = entity_dict["components"] = {}
    components = ComponentManager.get_components()
    for name, component in components.iteritems():
        component_values = getattr(entity, name)
        if component_values:
            component_data = None
            for field in component.saveable_fields:               
                if not component_data:
                    component_data = components_data[name] = {}               
                component_data[field] = getattr(component_values, field)
   
    return entity_dict


class DemoOutliner(SimpleOutliner):
   
    def get_data(self, world, identifier):
        if identifier == "PlayerCharacter":
            return (0, 0, 255, 1)
        else:
            return SimpleOutliner.get_data(self, world, identifier)
   
def main():
    global world
    PrintAction.register()
   
    app = RPGApplication(TDS)
    app.load_components("combined.yaml")
    app.register_components()
    app.load_actions("combined.yaml")
    app.register_actions()
    app.load_systems("combined.yaml")
    app.register_systems()
    app.load_behaviours("combined.yaml")
    app.register_behaviours();
    app.create_world()
    world = app.world
    view = GameSceneView(app)
    controller = DemoController(view, app, outliner=DemoOutliner())
    controller.listener.is_outlined = True
    controller.outliner.outline_ignore.append("PlayerCharacter")
    controller.outliner.outline_data = (173, 255, 47, 2)
    app.load_maps()
    world.read_object_db()
    world.import_agent_objects()
    world.load_and_create_entities()
    app.switch_map("Level1")
   
    script_system = getattr(world.systems, "scripting")
    statistic_system = world.systems.character_statistics
    statistic_system.load_statistics_from_file("statistics.yaml")
    player = app.current_map["PlayerCharacter"]
    player.CharacterStatistics.gender = "male"
    player.CharacterStatistics.primary_stats["ST"] = 75
    player.CharacterStatistics.primary_stats["CO"] = 60
    app.push_mode(controller)
    app.run()

Code: (rpg_application.py) [Select]
def switch_map(self, name):
        """Switches to the given map.

        Args:
            name: The name of the map
        """
        old_map = None
        if self.__current_map:
            old_map = self.__current_map.name
            self.__current_map.deactivate()
            self.__current_map = None
        if name is None:
            return
        if name in self.__maps:
            self.load_map(name)
            self.__current_map = self.maps[name]
            self.__current_map.activate()
            for callback in self.__map_switched_callbacks:
                callback(old_map, name)
        else:
            raise LookupError("The map with the name '%s' cannot be found"
                        % (name))

Code: (scriptingsystem.py) [Select]
    def on_map_switched(self, old_map, new_map):
        """Called when the application switches to a new map

        Arguments:

            old_map: The name of the old map

            new_map: The name of the new map
        """
        if GameVariables.registered_as:
            getattr(self.world.systems, GameVariables.registered_as).step(0)
        for script in self.__scripts.itervalues():
            if not "map_switched" in script.__dict__:
                continue
            script_globals = self.prepare_globals()
            script.__dict__.update(script_globals)
            script.map_switched(old_map, new_map)
Title: Re: Jim's problems
Post by: Beliar on July 06, 2014, 07:49:35 am
What fife version and fife-rpg version are you using?
Title: Re: Jim's problems
Post by: Jim on July 06, 2014, 08:06:31 am
Fife 3.5 and fiferpg 0.2. Just uninstalled and reinstalled both and the problem stays.
Title: Re: Jim's problems
Post by: Beliar on July 06, 2014, 10:30:31 am
ok, the method you need to change should be in demo_game_scene.py (or something called similar) in the demo directory.
Title: Re: Jim's problems
Post by: Jim on July 06, 2014, 11:14:00 am
Aaaaah, thanks so much!
Title: Re: Jim's problems
Post by: Beliar on July 06, 2014, 10:42:43 pm
No problem, if you have further questions/problems just ask.
Title: Re: Jim's problems
Post by: ocina on February 20, 2015, 05:55:40 am
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).
Title: Re: Jim's problems
Post by: fredroney on March 23, 2017, 10:03:45 am
cool