global ent_think_fly_forward = function( a_event ){ .move_pos( vertex( 0, 1) );};global ent_setup(){ ent = ent_create( 0, 0, vertex( 250, 0 ) ); // assign a 'think' event function ent.events["on_think"] = ent_think_fly_forward;};
Running that little script will produce a motion in an entity that moves it forward one step each game frame tick.
Entities now have a properties dictionary, allowing you to customise it in your own way.
ent.props["health"] = 100; ent.props["speed"] = 2;
This allows you to create functions to build specialist entities:
global ent_enemy_type_id = 1;global ent_create_enemy = function( a_position ){ ent = ent_create( ent_enemy_type_id, 0, a_position ); ent.props["health"] = 100; ent.props["shield"] = 50; ent.props["speed"] = 20; ent.events["on_think"] = ent_think_fly_forward; return ent;};global setup_ents = function(){ ent = ent_create_enemy( vertex(250,0) );};
And there we have it! Work is now centring on setting up the user-triggers trip events within the game. Events are pretty cool in script as you can have a single event object and assign properties to it like in the entities. So a positional trigger that fires an event to damage an entity would look like:
global trg_positional_test = function(){ ent = .props["entity"]; pos = .props["position"]; return ent.test_collision_point( pos );};global trg_positional_test_action = function(){ evt = evt_create( "on_damaged" ); evt.target = .props["entity"]; evt.params["damage"] = 20; evt_fire( evt );};global setup = function(){ trg = trg_create( trg_positional_test, trg_positional_test_action ); trg.props["entity"] = gm_get_player_entity(); trg.props["position"] = vertex(300, 400); trg.activate();}
Now when the player collides with the specified point he receives an "on_damaged" event (which he should handle)...
global ent_on_damaged = function( a_event ){ .props["health"] -= a_event.params["damage"];};
And there you go... The entity receives damage from the event. Naturally, the engine will provide you with some triggers (such as the entity-position-collide, entity-area-collide, timer triggers, etc).
What do you think?
It's been a while since I read your GM articles (have they made it to the front-page yet?) but can you have C-style #include statements?
Maybe I've not quite understood it correctly - but it seems theres quite a bit of typing for a relatively common/simple thing?
Scripts are awesome, but some way of getting "to the point" and being able to script the interesting parts without all the extra setup fluff would be useful [smile]
Being able to #include that boiler plate code could solve that.
Keep up the good work!
Cheers,
Jack