Hard Light Productions Forums
Modding, Mission Design, and Coding => The Scripting Workshop => Topic started by: k7g on November 06, 2014, 11:42:34 pm
-
Can anyone help with this one please?
Here whats happening:
I'm creating a custom script for ships (turret control / repair systems, etc.)
But I've come across an issue,
Here is a basically what I'm trying to do:
#On Game Init:
[
function ***()
]
#On Frame
[
call function ***()
]
I've looked out other scripts and that works fine, but when I try to do it, I get nil value errors when calling it. Is there something I missed here? :blah:
-
Here is a basically what I'm trying to do:
But is that really what you're trying to do? Because your syntax is all messed up, which is evident if you look at said other scripts. Posting your actual code would be more useful.
-
Here we go, just trying to get things working before i start getting tables and that in.
#Conditional Hooks
$Application: FS2_Open
$On Key Pressed: [[atc_KeyPressed.lua]]
$On Key Released: [[atc_KeyReleased.lua]]
$On Game Init:
[
ui_keyToggleFunctions = {}
InputStates = {}
ui_keyToggleFunctions["Up Arrow"] = function(val) InputStates.up = val end
ui_keyToggleFunctions["Down Arrow"] = function(val) InputStates.down = val end
ui_keyToggleFunctions["Left Arrow"] = function(val) InputStates.left = val end
ui_keyToggleFunctions["Right Arrow"] = function(val) InputStates.right = val end
ui_keyToggleFunctions["0"] = function(val) InputStates.zero = val end
function doInput()
if InputStates.up then
gr.setColor(200,200,200)
gr.drawString("Up Key pressed",1,20)
end
end
]
$On Frame:
[
doInput()
]
#End
-
"On Frame" scripts are evaluated every time gr_flip() is called; "On Game Init" scripts are evaluated towards the end of the initialization process. The "splash screen" is displayed towards the beginning of the initialization process (causing gr_flip() to be called, causing the evaluation of "On Frame" scripts). You're trying to call doInput() before it's been defined.
-
hmmm...
didn't know that one, i'm surprised its not mentioned on the wiki about the load order. (or I've missed it :blah:)
So, if make the script only call them at a mission start, that should fix the issue? due the fact its only running at the startup of FS2 atm.
edit: The script i'm looking has the following Hooks in it (besides the Game Init and On Frame)
$On HUD Draw
$State: GS_STATE_GAME_PLAY
$On Gameplay Start
and &On Mission End (I know how to implement this one)
-
You probably just want to replace "On Frame" with "On HUD Draw", unless you want to be displaying these messages during mainhalls...
-
I was just testing to make sure the script was activating and executing correctly.
And I think what you said about 'Game Init' being almost last when the game loads, I assume that you have the 'On Frame', execute the functions only when a mission starts and the HUD draws(via variables).
edit: It works.
By adding a variable to the 'On Frame' hook, it stops it executing its code until the game starts and the HUD is drawn. Now its time to start getting the script to find the player ship and starting populating some tables...