[Solved] Custom global function?

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
Ixnatifual

[Solved] Custom global function?

Post 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.
Last edited by Ixnatifual on Sun Sep 23, 2012 5:33 pm, edited 1 time in total.
User avatar
Shroom
Posts: 98
Joined: Tue Mar 27, 2012 6:37 pm
Location: UK

Re: Custom global function?

Post by Shroom »

If you name you main script entity globalFunctions for example, you would reference the function called notAgain() like so

globalFunctions.notAgain()

:geek:
Ixnatifual

Re: Custom global function?

Post by Ixnatifual »

It didn't occur to me you could call scripts on an entity through the dot operator. Problem solved :)
User avatar
Ethmo_Lux
Posts: 13
Joined: Thu Oct 11, 2012 6:35 pm
Location: Brussels (Belgium)

Re: [Solved] Custom global function?

Post 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. :)
Post Reply