Animation-CobLuaDifferences: Difference between revisions

From Spring
Jump to navigationJump to search
Knorke (talk | contribs)
lua vs cob, its on!
Line 27: Line 27:


'''Interaction with the rest of Spring'''<br>
'''Interaction with the rest of Spring'''<br>
COB: - Only basic stuff.<br>
COB: - Tipically only basic stuff, but there is a messy way of interacting with gadgets which must be written in a way to support COB interaction.<br>
Lua: + can use all the other Lua functions Spring has to offer.<br>
Lua: + can use all the other Lua functions Spring has to offer.<br>
Lua: + game logic (gadgets) is written in Lua, too. So you need to know Lua anyway.
Lua: + game logic (gadgets) is written in Lua, too. So you need to know Lua anyway.


'''Easy of use'''<br>
'''Ease of use'''<br>
COB: - requires recompiling the script with a compiler after each change. <br>
COB: - Requires recompiling the script with a compiler after each change.<br>
COB: - This compiler appears to be pretty buggy.<br>
COB: - This compiler appears to be pretty buggy.<br>
COB: - Compiled scripts are not readable for human eyes.<br>
COB: - Compiled scripts are not readable for human eyes, but can be decompiled.<br>
Lua: + A text editor is all you need. Many editors support Lua syntax highlighting.<br>
Lua: + A text editor is all you need. Many editors support Lua syntax highlighting.<br>
Lua: + Scripts are not compiled so it is easy to look at the scripts of other games for examples.<br>
Lua: + Scripts are not compiled so it is easy to look at the scripts of other games for examples.<br>
'''Script performance'''<br>
COB: + Faster for simple scripts that have no interaction with gadgets.<br>
COB: - Slower when interacting with gadgets, trickier to code such interaction.<br>
Lua: - Slower threading engine.<br>
Lua: + Faster when interacting with gadgets.<br>


===Conclusion===
===Conclusion===

Revision as of 10:19, 3 May 2011

Overview of differences between COB unit scripts and Lua unit scripts

This is only of interesst if you plan to port your COB scripts to Lua:

  • Units of measurement: Lua uses elmos and radians consistently.
  • Coordinate system: In Lua, coordinate system is same as world coordinate system, with all rotations right-handed. In COB, the moves along the x-axis and rotations around the z-axis have a different sign.
  • In Lua, Killed gets recentDamage and maxHealth as separate arguments. In COB, you get only the ratio recentDamage/maxHealth*100.
  • Where COB uses SetMaxReloadTime, Lua uses GetMaxReloadTime.
  • Where COB uses QueryLandingPadCount and QueryLandingPad, Lua uses QueryLandingPads
  • The x and z arguments to HitByWeapon, HitByWeaponId and RockUnit are given in (x, z) order in Lua, and the opposite order in COB.
  • BeginTransport and EndTransport take the height of the unit in COB and the unitID in Lua. (Use 'local height = Spring.GetUnitHeight(unitID)' to get the height.)
  • TransportDrop gets PACKXZ(x,z) in COB; in Lua, it gets the entire vector (x, y, z) as three arguments.
  • Where COB uses SetSpeed and SetDirection, Lua uses WindChanged and ExtractionRateChanged.
  • Lua does not have Go (this is called for activated extractors immediately after each SetSpeed call.)

Which one is better? Lua or COB unitscripts?

If you are starting a new project and wonder what script language to use, look at this list:
data types:
COB: - only basic variables.
Lua: + arrays, strings and tables.
This is quite important as it allows for easier creation of advanced scripts.

availability of examples, documentation
COB: + is/was used in Total Annihaltion. Lots of third party units were made for that game and maybe you can reuse some scripts.
COB: - unclear legal status of these scripts
COB: - Outside of the TA community, there are no tutorials and it is unknown.
Lua: + is also used in projects outside Spring, so it has more tutorials.
Lua: + The documentation on Spring specific Lua will probally get better, COB not.

Interaction with the rest of Spring
COB: - Tipically only basic stuff, but there is a messy way of interacting with gadgets which must be written in a way to support COB interaction.
Lua: + can use all the other Lua functions Spring has to offer.
Lua: + game logic (gadgets) is written in Lua, too. So you need to know Lua anyway.

Ease of use
COB: - Requires recompiling the script with a compiler after each change.
COB: - This compiler appears to be pretty buggy.
COB: - Compiled scripts are not readable for human eyes, but can be decompiled.
Lua: + A text editor is all you need. Many editors support Lua syntax highlighting.
Lua: + Scripts are not compiled so it is easy to look at the scripts of other games for examples.

Script performance
COB: + Faster for simple scripts that have no interaction with gadgets.
COB: - Slower when interacting with gadgets, trickier to code such interaction.
Lua: - Slower threading engine.
Lua: + Faster when interacting with gadgets.


Conclusion

Unless you already have lots of complex unit scripts by porting TA content, Lua is always better.
Contra to popular belief, COB is actually not easier to learn.

Hints

  • COB & LUS (LuaUnitScripts) can be reloaded ingame via /reloadcob %unitdefname, also LUS get reloaded with /luarules reload, too.