Page 1 of 1

[Solved] Custom global function?

Posted: Sun Sep 23, 2012 4:40 pm
by Ixnatifual
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.

Re: Custom global function?

Posted: Sun Sep 23, 2012 5:20 pm
by Shroom
If you name you main script entity globalFunctions for example, you would reference the function called notAgain() like so

globalFunctions.notAgain()

:geek:

Re: Custom global function?

Posted: Sun Sep 23, 2012 5:32 pm
by Ixnatifual
It didn't occur to me you could call scripts on an entity through the dot operator. Problem solved :)

Re: [Solved] Custom global function?

Posted: Sat Oct 13, 2012 1:06 pm
by Ethmo_Lux
Solved.

Thanks anyway. :D
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 :

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
And the called script entity :

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
Thanks. :)