Operation Flashpoint Dragon Rising OFDR Forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Easy guide to LUA in OFDR

Go down

Easy guide to LUA in OFDR Empty Easy guide to LUA in OFDR

Post by TheGeneral Mon 17 Dec 2012, 15:41

Breaking the Code

This guide is for those that are very new to Dragon Rising and want to venture into their own mission making. The details explained in this tutorial are aimed at those that know absolutley nothing about programming. It is not an indepth tutorial about LUA whatsoever. It is aimed at explaining how LUA connects with Operation Flashpoint Dragon Rising' Mission editor. If you already have experience with programming then this tutorial will be of no use to you. It is aimed at gamers who have NEVER coded a game before and are taking their first steps into coding and programming.

Operation Flashpoint Dragon Rising use a language called LUA for the editor. This enables all kinds of things to occur in the game that we create. As you get more proficient with the way the code works you will begin to figure out how things piece together. Mixing up alot of things like strings and variables together, mixing different types of bracket formats, using numbers, "if" statements and booleans. The level.lua is a blank page when you start and as long as you know how they work together then you can get a mission that could cost you about a thousand lines wittled down to about 600 (maybe?) depending on how big you plan to make it.
The help guide has a some more information on this and more information can be found here:LUA Scripting
Lets have a look a few details we will be using first.

Chunks

1. - these are the areas in the code where we make different events happen. They start with a function line. This denotes the event that is happening, for example; if you want your guys to do something once they board a helo you would use an onMount function. The first line would be written thus:

Code:
function onMount(vehicleName, unitName, echelonName)
   
end



All the code that is written within that chunk now, will only reference everything you want to follow once they have mounted the helo.
Each chunk will start with a function event, but every function event must finish with an "end". This closes the whole chunk or event so we can move on to the next event. Failing to use the closing "end" will contribute to your mission not exporting when you come to test it.

So lets break that down for ourselves:

  • The word "function" is the start of a new chunk and is known as a "keyword". We always use this if we want to begin a new event.
    • The event is what follows "function" such as onMount(vehicleName, unitName, echelonName).

    • The onMount is a script command that is the event you want something to happen in.

    • The parts in brackets are known as variables and are identifiying the units that are commanded in that event. Each function has a set number of variables it returns, for example; onMount returns three variables, onEnter returns two (onEnter(zoneName,unitName)). These variables can contain numbers, strings or tables.

    • The name of each variable can be whatever you want, however the Mission Editor will by default give them names to help you identify the information within. For example you could have onMount(mountedVehicle, mountingUnit, mountingEchelon) instead of the default names, and the function will still work.

  • These variables are used to give you the appropriate units or values to be used inside the function.
    Sounds abit complicated but you will understand more as you begin to use the functions more and experiment with it.



TheGeneral
TheGeneral
Admin

Points : 780
Reputation : 35
Join date : 2012-12-15

http://maniacaldog.wix.com/keepdralive

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum