Re: A few questions about scripting
Douglas Cox <[email protected]>
| Newsgroups | gmane.games.devel.sweng |
|---|---|
| Message-ID | <[email protected]> |
>
> By calling the "OnEnter" event in the script in a test.
>
True, I could possibly come up with a way to simulate the parameters passed
into the event, but they may be from something set in a previous event
depending on which other triggers the player entered. So without writing a
'bot' to run through the level to simulate everything a player might, we
have to go with our other unit test (his name is Trevor). I'm certainly
interested in hearing what you guys are doing for things like this though.
I was mainly just trying to point out that for some things, the compiler is
doing part of that unit test for me in a strongly-typed language.
Event based programming tends to wipe out type info anyway, since you get
> generic arguments to your handlers... and check their types at runtime.
>
It might wipe out the arguments' type, though that depends on your event
definition. But that does not make *using* those arguments less type safe
in a strongly-typed language:
void OnEnter( Object initiator )
{
Entity entity = (Entity)initiator; // yes a runtime cast is required and
will throw/assert/etc
entity.ammo = 100; // whoops, was supposed to be entity.weapon.ammo =
100;
entity.damageScale = 2; // whoops, was supposed to be
entity.weapon.damageScale = 2;
}
So in a dynamically typed language I get no errors for the 2 wrong lines.
Yes, I have to add a runtime cast. Am I fine with typing that line in trade
for the compiler telling me I made a mistake vs. running a bunch of unit
tests or playing 2minutes to get to the trigger, definitely.
Dynamically typed languages certainly let you do some cool stuff, and
usually let you write less code. We've just run into enough of these sort
of issues that, to us, having a strongly-typed language is a benefit.
-doug
_______________________________________________
Sweng-Gamedev mailing list
[email protected]
http://lists.midnightryder.com/listinfo.cgi/sweng-gamedev-midnightryder.com