[Solved] Custom global function?
[Solved] Custom global function?
Is it possible to define your own global function which you can call through script entities? This way I can avoid copy-pasting the same function into every level.
Last edited by Ixnatifual on Sun Sep 23, 2012 5:33 pm, edited 1 time in total.
Re: Custom global function?
If you name you main script entity globalFunctions for example, you would reference the function called notAgain() like so
globalFunctions.notAgain()

globalFunctions.notAgain()

Re: Custom global function?
It didn't occur to me you could call scripts on an entity through the dot operator. Problem solved 

Re: [Solved] Custom global function?
Solved.
Thanks anyway.
Thanks anyway.

SpoilerShow
May I misunderstood, but I try to call a function from another script entity with the dot but It doesn't work...
Here the calling the other :
And the called script entity :
Thanks. 
Here the calling the other :
Code: Select all
pnjName = "Victor"
dialEnd = "end of dialog"
dialog = {"Oh, so you come to see Victor! Afraid of Scotia's new toy ? Ha ha!", "Why afraid? Look at Victor. Myself could use a shapechanger! Ha ha ha!", "You show Victor what you want to buy. Maybe you show Victor what you sell, OK ?", dialEnd}
secondDialog = {"You again come to see Victor ?", dialEnd}
byeDialog = {"You again come visit, no?", dialEnd}
fromShop = false
function victorSay()
fromShop =globalDialogs.pnjDialog(dialog, fromShop, pnjName)
if dialog ~= secondDialog then
dialog = secondDialog
end
end
function victorBye()
globalDialogs.pnjBye(byeDialog, fromShop, pnjName)
end
Code: Select all
function pnjTell(dialog, pnjName)
local dialNumber = 1
hudPrint("")
if dialog[dialNumber] ~= dialEnd then
hudPrint(pnjName.." : "..dialog[dialNumber])
dialNumber = dialNumber + 1
while dialog[dialNumber] ~= dialEnd do
hudPrint(dialog[dialNumber])
dialNumber = dialNumber + 1
end
end
end
function pnjDialog(dialog, fromShop, pnjName)
if not fromShop then
pnjTell(dialog, pnjName)
fromShop = true
end
return fromShop
end
]function pnjBye(dialog, fromShop, pnjName)
if fromShop then
pnjTell(byeDialog, pnjName)
fromShop = false
end
return fromShop
end
