Hello, we apologize but forum registrations are non-functional at this time. This issue should be fixed around mid-December. Until then, please stop by our Discord channel if you'd like to get in touch with the team. Thanks!

Change dialoque references

For discussion of the code running behind the game

Moderator: Staff

Post Reply
nemesis
Senior Member
Posts: 157
Joined: Fri Apr 29, 2011 1:53 am
Location: Sachsen/Germany

Change dialoque references

Post by nemesis » Tue May 24, 2011 6:49 am

During lunch I was thinking about how to change the dialoque, a sprite have on a map.

One example is in the river_access_area, where the knight at the short passage (id=2004) should have a dialoque available before the passage collapses (id=30) and one afterwards (id=31). Right now, nothing is implemented to replace an existing dialoque with a new one.

As I think, there are two possibilities doing this:

1. Using a script event
2. Using a new event type. (DialogueChangeEvent(sprite_id, list_of_dialogue_ids)

Basically, the second one would be the better option, if this event is needed several times.

The first one I've tried, implementing an new function

Code: Select all

void MapSprite::ClearDialogues() {
    _dialogue_references.clear();
}
with the corresponding lua script

Code: Select all

map_functions[15] = function()
    knight_talk_sprite:ClearDialogues();
    knight_talk_sprite:AddDialogueReference(31);
end
This works well but has the disadvantage that everytime such an event is used, a function needs to be created.

What do you think is the better way to do this?
User avatar
Roots
Dictator
Posts: 8669
Joined: Wed Jun 16, 2004 12:07 pm
Location: Austin TX
Contact:

Re: Change dialoque references

Post by Roots » Tue May 24, 2011 1:37 pm

Yeah I hadn't gotten around to looking into this yet, but I was pretty sure I was going to have to write a new function in order to do this. I think writing a script event would be a better option, because the hard-coded way forces the removal of all dialogue references. We may only want to remove one dialogue reference and replace it with another, or we may want to remove all references and not add any new ones. So I think the case we're talking about here is not generic enough to warrant having its own event class.


I think in addition to the ClearDialogues() function (I'd prefer it to be named ClearDialogueReferences() ), we should have another function called RemoveDialogueReference(uint32 dialogue_id) that removes a dialogue reference with the provided id. This will give us full control over the dialogue references of a sprite in Lua. Also note that both ClearDialogueReferences() and RemoveDialogueReferences() should be calling UpdateDialogueStatus() after they've modified the _dialogue_references container. This function updates some other internal members that display the dialogue bubble and allow dialogues to occur in the first place.


Once that is done and both ClearDialogueReferences() and RemoveDialogueReference() are commented and are bound to Lua, go ahead and commit it. Thanks for taking initiative on this. :approve:
Image
nemesis
Senior Member
Posts: 157
Joined: Fri Apr 29, 2011 1:53 am
Location: Sachsen/Germany

Re: Change dialoque references

Post by nemesis » Wed May 25, 2011 8:47 am

Okay, I did a commit.


I also added

Code: Select all

UpdateDialogueStatus();
to the existing

Code: Select all

void MapSprite::AddDialogueReference(uint32 dialogue_id)
for the case, a dialogue is added by an event in order to pop up the dialogue bubble.
User avatar
Roots
Dictator
Posts: 8669
Joined: Wed Jun 16, 2004 12:07 pm
Location: Austin TX
Contact:

Re: Change dialoque references

Post by Roots » Sat May 28, 2011 9:09 pm

nemesis wrote:Okay, I did a commit.

I also added

Code: Select all

UpdateDialogueStatus();
to the existing

Code: Select all

void MapSprite::AddDialogueReference(uint32 dialogue_id)
for the case, a dialogue is added by an event in order to pop up the dialogue bubble.
There is one minor problem with that. When you call UpdateDialogueStatus(), it checks that all dialogue references are valid (that is, that there is a dialogue with that ID stored by the dialogue supervisor). However, in our Lua load functions we construct our sprites first and then our dialogues, and when we construct our sprites we also add their dialogue references. But the dialogues haven't been constructed yet, so that generates a bunch of warnings about invalid dialogue references, although it doesn't cause any other run-time problems because those dialogues are added later in the loading sequence.


But it makes sense to call UpdateDialogueStatus() from AddDialogueReference() like you've done, because if we have a script that is adding a new dialogue reference we absolutely want to make sure it also updates the dialogue status. For now, I left a comment in the AddDialogueReference() function about this and noted that we should eventually deal with it. Its a minor issue though so we can let it slide for the time being.
Image
nemesis
Senior Member
Posts: 157
Joined: Fri Apr 29, 2011 1:53 am
Location: Sachsen/Germany

Re: Change dialoque references

Post by nemesis » Tue Jun 14, 2011 8:36 am

Yes, good point.

Basically, we have two options.
  • Remove the call of UpdateDialogueStatus() from the functions and release it the luabind so the user has to call it in the map file. Bad option, since simply, the user may forget it and is forced to go deep into the system.
  • Put a flag in AddDialogueReference whether this is the initial assignment of the dialogs.
  • Simply define the dialogs before the sprites in the map file.
I know, generally this is a very minor issue, but I'm interested in the opinion of more capable programmers than me.
User avatar
Roots
Dictator
Posts: 8669
Joined: Wed Jun 16, 2004 12:07 pm
Location: Austin TX
Contact:

Re: Change dialoque references

Post by Roots » Tue Jun 14, 2011 12:16 pm

I like the second option the best (having an alternative AddDialogueReference() function that ignores the reference checking). I agree that the first one is a bad option for the reasons that you stated, and I dislike the third because I don't want to introduce any definition order dependencies in our map files. So maybe we could just bind an additional function to Lua called "LoadDialogueReference()" that operates the same as AddDialogueReference(), but doesn't do the reference checking stuff. Yeah, that's what I think we should do.


On a related note to this, something that we need to eventually add to our map loading code is a call to a function called "ValidateMapData()" or something that goes over all of the objects, sprites, dialogues, events, zones, etc. and prints warning messages for any potential issues that it finds. In fact, if any issues are fond then the game should prevent the map from loading entirely and force the developer to fix the issue(s) reported.
Image
nemesis
Senior Member
Posts: 157
Joined: Fri Apr 29, 2011 1:53 am
Location: Sachsen/Germany

Re: Change dialoque references

Post by nemesis » Tue Jun 14, 2011 12:41 pm

Roots wrote:On a related note to this, something that we need to eventually add to our map loading code is a call to a function called "ValidateMapData()" or something that goes over all of the objects, sprites, dialogues, events, zones, etc. and prints warning messages for any potential issues that it finds. In fact, if any issues are fond then the game should prevent the map from loading entirely and force the developer to fix the issue(s) reported.
Maybe this can be added to the editor, which would strongly ease working on such bugs. But this is only one though and nothing I would work on... :angel:

But you are completely right, some

Code: Select all

"ValidateMapData()"
function is really necessary, especially for future large maps with lot of events.
Post Reply