Hard Light Productions Forums
Modding, Mission Design, and Coding => The Scripting Workshop => Topic started by: zookeeper on March 05, 2015, 07:59:06 am
-
Maybe this would better belong in the modding or FRED subforum, please move if so.
In FotG we needed to detect specific physical keypresses in a couple of places, and in such a case key-pressed doesn't work because the player might have bound their keys differently. I wrote a very simple script to allow that to be done, so I might as well post it here in case someone finds it useful:
#Conditional Hooks
$Application: FS2_Open
$On Game Init: [
keypressed = function(keyname)
if keypresses[keyname] then
return 1
else
return 0
end
end
keyreset = function(keyname)
if keypresses[keyname] then
keypresses[keyname] = nil
end
end
]
$State: GS_STATE_GAME_PLAY
$On Gameplay Start: [
keypresses = {}
]
$On Key Pressed: [
local key = hv.Key
keypresses[key] = true
]
#End
Put that in keypresses-sct.tbm, after which you can use the two functions just like key-pressed and key-reset:
$Formula: ( when
( >
( script-eval-num
"keypressed('Backspace')"
)
0
)
( play-sound-from-table 0 0 0 "78" )
)
+Name: PlaySoundOnBackspace
+Repeat Count: 1
+Interval: 1
$Formula: ( when
( has-time-elapsed 5 )
( script-eval "keyreset('Backspace')" )
)
+Name: ResetBackspace
+Repeat Count: 1
+Interval: 1
The function returns 0 if the key has not been pressed, and 1 if it has been, hence the use of the > operator and script-eval-num.
-
Is there an appropriate place to put this in the wiki?
-
Is there an appropriate place to put this in the wiki?
Well, that would be the Scripting Examples category (http://www.hard-light.net/wiki/index.php/Category:Scripting_Examples). I don't know how I'm supposed to add a new page though.
-
I usually create a new page by creating a link to the "doesn't exist yet" new page on an existing page. That gives you a link which lets you add content to the "doesn't exist yet" page and, well, create it. Personally I think that's counter-intuitive, I'm more used to wiki's that have a "create page" button somewhere.
-
I usually create a new page by creating a link to the "doesn't exist yet" new page on an existing page. That gives you a link which lets you add content to the "doesn't exist yet" page and, well, create it. Personally I think that's counter-intuitive, I'm more used to wiki's that have a "create page" button somewhere.
Well, yeah, I figured I could do that, but looking at how the existing script pages don't have any pages linking to them, I also figured that they were likely created via some other means (as opposed to creating a link to page B on some random page A, adding page B, removing link from page A).
-
Well, I've learned something. There's a bunch of different ways to create a page without creating a dummy link first, using the search box (https://meta.wikimedia.org/wiki/Help:Starting_a_new_page#Starting_a_new_page_from_a_search) seems fairly easy.
-
I have created new pages by just typing a page name in the URL bar. FS2 WebUI Standalone (http://www.hard-light.net/wiki/index.php/FS2_WebUI_Standalone) and Release Build Process (http://www.hard-light.net/wiki/index.php/Release_Build_Process) I think were both created in that manner.
-
We need a wiki page on how to make wiki pages. lol