Jump to content

Understanding defining your own functions and calling them in DCS.


Recommended Posts

Posted

I’m in the process of trying to learn Lua and Scripting in DCS.  What I would like to do is to send a message to the client.  90% of that is generic information.  The client specific part would be the players name and the type of helicopter they are in.  I know how to get both of those.

 

I am not sure how functions are called or used by DCS  since I’m still learning about those.

 

What I am wondering is if I could implement this by using a function that contains most of the generic message. And just give pass it the client specific information.  My thought is to have the function in a file that is loaded at Mission start and then call that function via triggers in the ME.  SO thoughts of the flow are shown below.

 

So my questions are:

1)      Is this how functions basically work in the DCS Scripting environment

2)      Will my basic approach work.

3)      Will the function be "global" defined in this manner, and is that OKI?.

I’m not looking for a direct solution , just pointers for me to go research and test.  Am I'm on the right track, or totally missed the boat.

 

Thanks in Advance

 

Script file – Load this at mission start.

<><><><> 

function Message_out  ( Group_ID, C_Name, Helo_type)

trigger.action.outTextForGroup(Group_ID, '\n\nWelcome  ' .. C_Name .. ' \n\nYou are in a ' .. Helo_type, 15)

end

<><><>  

 

Do Script – Performed as an action when ME conditions are met

Local Group_ID  = ….

Local C_Name  = ….

Local  Helo_type  = ….

Message_out ( Group_ID, C_Name, Helo_type)  -- this is meant to call the function with the necessary parameters.

----------------

AKA_Clutter

 

Win 10 Pro, Intel i7 12700k @4.6 GHz, EVGA RTX 3080  FTW, Ultra 64 GB G.Skill DDR4 3600 RAM, Acer 27" flat screen, HP Reverb G2, TM Warthog HOTAS with Virpil warBRD base, MFG Rudder Pedals, Virpil TCS Rotor Base with AH-64Dcollective, TrackIR 5 Pro w/Vector Expansion, PointCTRL.

Posted

Yes once a function is declared it is accessible based on the locality it was defined in. Basically it'll be global as long as you don't add local in front of it. Also in lua it matters that it is local and not Local, capitalization matters. 

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Posted
9 hours ago, Grimes said:

Yes once a function is declared it is accessible based on the locality it was defined in. Basically it'll be global as long as you don't add local in front of it. Also in lua it matters that it is local and not Local, capitalization matters. 

Thanks Grimes.  And yes syntax matter as I keep learning.  🙂  That is what I get from typing the message in MS Word first.

 

Now to go and see if I can actually do what I want to do.

----------------

AKA_Clutter

 

Win 10 Pro, Intel i7 12700k @4.6 GHz, EVGA RTX 3080  FTW, Ultra 64 GB G.Skill DDR4 3600 RAM, Acer 27" flat screen, HP Reverb G2, TM Warthog HOTAS with Virpil warBRD base, MFG Rudder Pedals, Virpil TCS Rotor Base with AH-64Dcollective, TrackIR 5 Pro w/Vector Expansion, PointCTRL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...