Josh Posted December 1, 2009 Share Posted December 1, 2009 I want to make sure the system can handle complicated interactions. Here is an example where a bullet shoots an enemy. I added an imaginary extra "sender" parameter to make it easier: Bullet/player script: enemy:SendMessage("hurt",0,"-5") Enemy script: function ReceiveMessage( message, extra, sender ) if message="hurt" self.health=self.health-tonumber(extra) if self.health<=0 then self:Kill() sender:SendMessage("addscore")--Add to the killer's fragcount else self.model:EmitSound(sound_ouch) end end end What other scenarios can you think of that might be difficult? As far as I can tell, this system can handle everything, but I want to make sure. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rick Posted December 1, 2009 Share Posted December 1, 2009 (edited) I'll make it easier. Here is one that I will be trying this weekend. You control in first person mode a player model When you collide with a trigger the following happens You lose control of the player The camera snaps to a pivot and points at the player model Music starts to play The player model moves to pivot2 Once there play a sound file of him talking Once that's complete move to pivot3 Once there play another sound file Once finished move camera back to fps and give back control I think I have an idea of how to make this work without globals and with targets. I'm going to try it your way I guess Edited December 1, 2009 by Rick Quote Link to comment Share on other sites More sharing options...
Josh Posted December 1, 2009 Author Share Posted December 1, 2009 That example is just a lot of different things going on, but nothing itself is very complicated: Trigger sets a key in the player model: SetKey("controlmode","auto") Trigger sets the camera model's target to the player. The camera script follows the target, when one exists. Trigger sends a message to a sound entity to play the music. Player moves to his target until he reaches it, and some more events are triggered. ...and so on. A bullet hitting a player, hurting them, and updating the owner's score was about the most complicated single interaction I could think of. Any other ideas? One advantage of this system is it encourages you to create a defined set of actions with the messages, instead of making spaghetti code. One disadvantage is when you have something like the roads, and you want to tell if a wheel of a car lies on the road. You need to communicate with the road script, but how do you get that info back? That is where it gets sticky. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rick Posted December 1, 2009 Share Posted December 1, 2009 One advantage of this system is it encourages you to create a defined set of actions with the messages, instead of making spaghetti code. The disadvantage is when you have to create a sequence of events that follow one after the other waiting until the one before it is complete, it starts making speghetti code with all the messages you are sending back and forth. And how specific and not general the messages are handled. The "...and so on" part you skipped is the part that starts waiting for things to be complete before continuing on. That's the hard part. Also, would you rather add a bunch of triggers to your scene or just use a simple script? I'll start working on this today because I think an example is needed. Quote Link to comment Share on other sites More sharing options...
Josh Posted December 1, 2009 Author Share Posted December 1, 2009 You're planning to write a unique script to make all those events occur? I think it makes more sense to have a set of rules so the artist can place objects and adjust settings without writing a new script for each map. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rick Posted December 1, 2009 Share Posted December 1, 2009 It would be a script that gives a set of functions to allow these kind of interactions to happen. Think of these functions are the rules as to how things work. I think it makes more sense to have a set of rules so the artist can place objects and adjust settings without writing a new script for each map. Writing a script for each interaction is the same as having to place all these triggers for each interaction. The same amount of work is put in. It's just different work. From what I've read scripting is a skill that mappers are required to know these days because it allows much more functionality. The script would be 1 function that flows how it would read: Do step 1 Do step 2 after step 1 Do step 3 after step 2 etc One of the features this opens up is that the script that runs the interaction can be dynamic. So you could setup 3 different sequence of events and randomly choose or choose based on other actions what gets ran. You just point to a different script or randomly choose one. I'll add that also, because I think that could lead to some very cool gameplay. The interactions wouldn't need to be hardcoded in the map. The supporting entities would need to be there but the script could use them differently depending on what script is ran. Quote Link to comment Share on other sites More sharing options...
Josh Posted December 1, 2009 Author Share Posted December 1, 2009 I'm going to do some experiments with a single lua state. It will make scripting harder, and you will have to manually clean everything up yourself, but it would allow shared data like this: player.enemy.bullet:shoot() Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rick Posted December 1, 2009 Share Posted December 1, 2009 The more I play around with ideas I think I can do this with targets and non globals. It won't be exactly how I envisioned but it should work about the same. Will get an example out as soon as I can. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.