External Scripts / Organisation
External Scripts / Organisation
hey,
maybe some of the script gurus can help: i like to keep the bulk of my scripts in external files. now this seems to be impossible, i can only put item/object/etc. definitions into external lua scripts. did i forget something?
example: i have a custom barrel and would like to do: onDie = fiz_spawnLoot()
now the fiz_spawnLoot() would be defined in a external lua script and NOT in a script entity. is this even possible? the script is quite long and will be modified/updated often. also i would like to call this function from various hooks (onDie of objects and monsters etc.)
I saw something similiar in the log framework, but did not fully grasp its functionality.
maybe some of the script gurus can help: i like to keep the bulk of my scripts in external files. now this seems to be impossible, i can only put item/object/etc. definitions into external lua scripts. did i forget something?
example: i have a custom barrel and would like to do: onDie = fiz_spawnLoot()
now the fiz_spawnLoot() would be defined in a external lua script and NOT in a script entity. is this even possible? the script is quite long and will be modified/updated often. also i would like to call this function from various hooks (onDie of objects and monsters etc.)
I saw something similiar in the log framework, but did not fully grasp its functionality.
--
Fhizban's Asset Repository - the place where you find all my LoG contributions:
viewtopic.php?f=14&t=3904
Fhizban's Asset Repository - the place where you find all my LoG contributions:
viewtopic.php?f=14&t=3904
Re: External Scripts / Organisation
AFAIK you can't, but it's really not that much of a hassle to use script entities. You can gather them on top of level 1 or something in the corner and give them all descriptive names. Easier to fix errors that way as wellFhizban wrote:hey,
maybe some of the script gurus can help: i like to keep the bulk of my scripts in external files. now this seems to be impossible, i can only put item/object/etc. definitions into external lua scripts. did i forget something?
example: i have a custom barrel and would like to do: onDie = fiz_spawnLoot()
now the fiz_spawnLoot() would be defined in a external lua script and NOT in a script entity. is this even possible? the script is quite long and will be modified/updated often. also i would like to call this function from various hooks (onDie of objects and monsters etc.)
I saw something similiar in the log framework, but did not fully grasp its functionality.
-Wolfrug
Try my Mordor: Depths of Dejenol LoG-ification. Feedback much appreciated!
Re: External Scripts / Organisation
thanks wolfrug, do you mean they are global? so i dont have to place the same script entity on each dungeon level? yiehaa!
--
Fhizban's Asset Repository - the place where you find all my LoG contributions:
viewtopic.php?f=14&t=3904
Fhizban's Asset Repository - the place where you find all my LoG contributions:
viewtopic.php?f=14&t=3904
Re: External Scripts / Organisation
Script entities are global, and you can even refer to them from "outside" scripts (say, for example, in a party hook defined in init.lua).
What I usually do for any scripting entity of size (not the smallish ones containing hudPrints and little more):
Another point on my workflow if it can be of help to anyone: I've created a file system junction so that my dungeons are all also inside the dropbox folder for constant backup
What I usually do for any scripting entity of size (not the smallish ones containing hudPrints and little more):
- Have a file whose name is the name of the scripting entity, prefixed with underscore
- Whenever I want to make some change, I change it in the lua file and copy/paste it in the entity
Another point on my workflow if it can be of help to anyone: I've created a file system junction so that my dungeons are all also inside the dropbox folder for constant backup
Waking Violet (Steam, PS4, PSVita, Switch) : http://www.wakingviolet.com
The Sunset Gate [MOD]: viewtopic.php?f=14&t=5563
My preciousss: http://www.moonsharp.org
The Sunset Gate [MOD]: viewtopic.php?f=14&t=5563
My preciousss: http://www.moonsharp.org
Re: External Scripts / Organisation
You can use one script entity, and call/trigger it multiple times from multiple sources.I used it for party exp awards, probably 30 triggers on that entity throughout the dungeon. I also use a global SE for Ixnatifuals randomizing tomes.
Currently conspiring with many modders on the "Legends of the Northern Realms"project.
"You have been captured by a psychopathic diety who needs a new plaything to torture."
Hotel Hades
"You have been captured by a psychopathic diety who needs a new plaything to torture."
Hotel Hades
Re: External Scripts / Organisation
in-editor script entities have very big advantage of non-crash-inducing debugging. I would take five times as long to make my scripts work if I had to restart the editor for every little typo, not to mention even being able to figure out what I did wrong in the first place.
Finished Dungeons - complete mods to play
Re: External Scripts / Organisation
Great, great point Komag. The editor names any flaws in a script, and points them out to you individually, until they all work. Big help that is when your heads all muddled with strings and numbers.
Currently conspiring with many modders on the "Legends of the Northern Realms"project.
"You have been captured by a psychopathic diety who needs a new plaything to torture."
Hotel Hades
"You have been captured by a psychopathic diety who needs a new plaything to torture."
Hotel Hades
Re: External Scripts / Organisation
I've looked at LOG framework code and its authors were able to hack it a little bit to achieve the effect of including external scripts.
I will write a short tutorial about how they do it, and how anyone can make use of external scripts. It's an advanced topic, so be aware of it.
1. Suppose we create an external script in mod_assets/scripts directory called hello.lua and we write some code in it.
2. Then we have to import this file in init.lua file in scripts directory.
3. Now comes the hack. We have to spawn the code somehow and they use an entity for that. In their case it's dungeon_door_metal, but I gues it can be almost any kind of object. We will add this code to our hello.lua script.
In onOpen method of this object, we spawn a script. The last attribute of spawn method is the name by which we can access our code later. We then set a source to obj.
4. obj has to be a string containing our code. I think the game mechanics then use some kind of eval on this later. We need to encapsulate our code in multiline string. So we will replace our hello function with this.
5. Finally in the log dungeon editor we create a script that loads this entity, in this case a door, and we call it's open function. This will call the onOpen method and our code will be spawned.
We then don't need the door so we can destroy it.
6. As I metioned in a step 3, we can now access our code through a global variable hello (that's what we passed to the spawn method) anywhere in our scripts.
This code will call the function hello in our external script and print 'Hello world' to the screen.
And that's it. We can now have our code structured in separate scripts.
EDIT:
Fixed a few typos and rename some variables to make it more understandable.
I will write a short tutorial about how they do it, and how anyone can make use of external scripts. It's an advanced topic, so be aware of it.
1. Suppose we create an external script in mod_assets/scripts directory called hello.lua and we write some code in it.
Code: Select all
function hello()
print('Hello World')
end
Code: Select all
-- import standard assets
import "assets/scripts/standard_assets.lua"
-- import custom assets
import "mod_assets/scripts/hello.lua"
Code: Select all
cloneObject{
name = "HelloDoor",
baseObject = "dungeon_door_metal",
onOpen = function()
spawn("script_entity", 1,1,1,0,'hello')
hello:setSource(obj)
end
}
4. obj has to be a string containing our code. I think the game mechanics then use some kind of eval on this later. We need to encapsulate our code in multiline string. So we will replace our hello function with this.
Code: Select all
local obj = [[
function hello()
print('Hello World')
end
]]
Code: Select all
spawn("HelloDoor", 1,1,1,0,'helloInit')
helloInit:open()
Code: Select all
helloInit:destroy()
Code: Select all
function test()
hello.hello()
end
And that's it. We can now have our code structured in separate scripts.
EDIT:
Fixed a few typos and rename some variables to make it more understandable.
Last edited by 3socks on Mon Nov 05, 2012 5:10 pm, edited 2 times in total.
Re: External Scripts / Organisation
Excellent tutorial! Thanks for sharing this.3socks wrote:I've looked at LOG framework code and its authors were able to hack it a little bit to achieve the effect of including external scripts.
I will write a short tutorial about how they do it, and how anyone can make use of external scripts. It's an advanced topic, so be aware of it.
Just to clarify one thing... does the code in step 4. actually replace the code we wrote in step 1. in our external lua file?
Puzzle Frameworks - http://www.grimrock.net/forum/viewtopic.php?f=14&t=4564
Magic Pack - https://www.nexusmods.com/grimrock/mods/70
Area of Effect Spell System - http://www.grimrock.net/forum/viewtopic ... 150#p44382
Magic Pack - https://www.nexusmods.com/grimrock/mods/70
Area of Effect Spell System - http://www.grimrock.net/forum/viewtopic ... 150#p44382
Re: External Scripts / Organisation
@3socks thank you so much! this is exactly what i was looking for. I will check it out after work.
--
Fhizban's Asset Repository - the place where you find all my LoG contributions:
viewtopic.php?f=14&t=3904
Fhizban's Asset Repository - the place where you find all my LoG contributions:
viewtopic.php?f=14&t=3904