reusable script objects for spawning multiple objects

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
chaoscommencer
Posts: 119
Joined: Sun Jan 05, 2014 7:48 pm

reusable script objects for spawning multiple objects

Post by chaoscommencer »

Long title ;). I was wondering if anyone knows whether it is possible to design script objects in lua files with the script written in the object definition? If this is possible, how would one go about doing it? I was considering a response in Germanny 's thread when the topic of having multiple objects in one came up. I looked at ScriptEntity's properties and did not see one for the actual script. Any examples would be appreciated :).
Thanks!
Working on a dungeon that displays a massive collection of assets while sorting them into convenient reusable plugin format (concept from some of leki's mods). Will contribute some of my own models as well eventually and follow that with custom dungeon.
User avatar
Diarmuid
Posts: 807
Joined: Thu Nov 22, 2012 6:59 am
Location: Montreal, Canada
Contact:

Re: reusable script objects for spawning multiple objects

Post by Diarmuid »

do you mean, having scripts externally like the LoG framework allows you to? (having a normal script entity, but with the source in an .lua instead of in the editor/dungon.lua)

Or are you talking about a cloneObject of script_entity, which would come preloaded with a script?

EDIT: If you want the latter, you could clone script_entity to a custom object name, put the new object everywhere you want in the editor, and have a master script scan the dungeon for these at startup and call a :setSource(source) on them to fill them with the required code. I don't think it can be bundled together outside.
chaoscommencer
Posts: 119
Joined: Sun Jan 05, 2014 7:48 pm

Re: reusable script objects for spawning multiple objects

Post by chaoscommencer »

Thanks for the reply Diarmuid. The intention was indeed to have a renamed script object come preloaded with a script. Though they wouldn't technically be preloaded with the solution you provided, that is a great idea and should work.

Now I just need to know the best place for storing a table of scripts. Any ideas on that? I noticed the LoG framework has a data module; could they be stored there, and, if so, how? (I guess I'm not incredibly familiar with how to use the fw yet, but it seems to have a lot of convenient functionality.)

Alternatively, is it possible to pass a lua file path as the parameter to setSource?
Working on a dungeon that displays a massive collection of assets while sorting them into convenient reusable plugin format (concept from some of leki's mods). Will contribute some of my own models as well eventually and follow that with custom dungeon.
User avatar
Diarmuid
Posts: 807
Joined: Thu Nov 22, 2012 6:59 am
Location: Montreal, Canada
Contact:

Re: reusable script objects for spawning multiple objects

Post by Diarmuid »

Sorry, I didn't see you did reply to this... Well you could load your .lua file through the fw and have it itself fill in the code. Example of what you would put in an .lua file:

Code: Select all

fw_addModule('codeFiller',[[

scriptsCode = {
	scriptName1 = [[
	
		lua script code
		[...]
	
	]],
	scriptName2 = [[
	
		lua script code
		[...]
	
	]]
}

function autoexec()
	for e in grimq.fromAllEntitiesInWorld():toIterator() do
		for scriptName, scriptSource in pairs(scriptsCode) do
			if e.name == scriptName then
				e:setSource(scriptSource);
			end
		end	
	end
end

]])
This would create at startup a script_entity named codeFiller with that script inside, then the autoexec would get called and fill the rest of the objects.
Post Reply