Jump to content

Advanced interactions


Josh
 Share

Recommended Posts

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.

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

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

Edited by Rick
Link to comment
Share on other sites

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.

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

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.

Link to comment
Share on other sites

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.

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

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.

Link to comment
Share on other sites

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

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...