~Advanced Scripting and Editor Help

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
Mysterious
Posts: 226
Joined: Wed Nov 06, 2013 8:31 am

Re: ~Advanced Scripting and Editor Help

Post by Mysterious »

Now this is where Akroma takes over and blows us all away - Rem his last Mod? :)
dancodan
Posts: 19
Joined: Sun Apr 29, 2012 1:38 pm

Re: ~Advanced Scripting and Editor Help

Post by dancodan »

Hey Snowy, I really need your help.

I started to look in to scripting yesterday and I have managed to do some activation of torches, text particles et cetera.
I've read the information on the Modding section but I have my first real road block, and google didnt help me this time.

I am trying to get an alcove to spawn a water flask (the water is just a test)

I created a script like this

function addWater()
mine_alcove_3.surface:addItem(water_flask_1.item)

end

and as you probably already know, I get this result

function addWater()
mine_alcove_3.surface:addItem(water_flask_1.item) <- Attempt to index global "water_flask_1" (a nil value) x

end

I assume that when the script is trying to create the water flask, it can't find it, cause I haven't indexed it.
I also assume that I should use the "define object" function in a global script that I have somewhere on the level, but I have no clue how to do that.

I would really appreciate some help, because this would open up the world to me. Once I know how to summon objects I can start to do all kind of cool puzzles. (After I learned how to check a surface for a certain object, the puzzles will get even cooler)

Thanks in advance, mate.

regards
Daniel
User avatar
Mysterious
Posts: 226
Joined: Wed Nov 06, 2013 8:31 am

Re: ~Advanced Scripting and Editor Help

Post by Mysterious »

Yo bro yeah water_flask_1 is not defined so do this:

Code: Select all

function addWater()
	mine_alcove_3.surface:addItem(water_flask.item)

end
errr I hope imam right on this yeah :)
dancodan
Posts: 19
Joined: Sun Apr 29, 2012 1:38 pm

Re: ~Advanced Scripting and Editor Help

Post by dancodan »

Mysterious wrote:Yo bro yeah water_flask_1 is not defined so do this:

Code: Select all

function addWater()
	mine_alcove_3.surface:addItem(water_flask.item)

end
errr I hope imam right on this yeah :)

I don't understand. That's exactly what I did, which didnt work cause the water_flask isnt defined.
Or am I missing something ?

Regards
Daniel
DrKojak
Posts: 23
Joined: Fri Oct 24, 2014 11:19 am

Re: ~Advanced Scripting and Editor Help

Post by DrKojak »

How do you code a working mimic in its 'dormant' state, in a set location with loot?

One that you try to open only to stick your head into its mouth and have it get up an attack
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: ~Advanced Scripting and Editor Help

Post by Komag »

use " ", such as "water_flask"
Finished Dungeons - complete mods to play
dancodan
Posts: 19
Joined: Sun Apr 29, 2012 1:38 pm

Re: ~Advanced Scripting and Editor Help

Post by dancodan »

Im so sorry, but I am totally lost

I tried

function addWater()
mine_alcove_3.surface:addItem "water_flask"()

end

and

function addWater()
mine_alcove_3.surface:addItem "water_flask"

end

and

function addWater()
mine_alcove_3.surface:addItem"water_flask.item"()

end

and

function addWater()
mine_alcove_3.surface:addItem"water_flask".item()

end

and

function addWater()
mine_alcove_3.surface:addItem"water_flask.item"

end

and

function addWater()
mine_alcove_3.surface:addItem(water_flask.item)

end

and

function addWater()
mine_alcove_3.surface:addItem("water_flask.item")

end

and

function addWater()
mine_alcove_3.surface:addItem("water_flask".item)

end



And all are wrong. Can anyone write the working code for this? It looks like it should be simple but I can't get the game to understand what a water flask is...
Or am I working the wrong angle here?
I'm trying to learn basic scripts by copying and testing. But this one just refuse to work... and it seems so simple. It must be a mechanic I am unaware of. Like defining objects or where to put " " when objects are undefined.

Also Komag, might it be that Grimrock 2 added .item after all items, so now you need to write water_flask.item et cetera that is screwing up the script when it tried to understand what "water_flask" is ?
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: ~Advanced Scripting and Editor Help

Post by NutJob »

mine_alcove_3.surface:addItem(water_flask_1.item)

you're not referencing the globally defined object. you reference your object. so most likely "_1" if you only spawned one, thus far.
Last edited by NutJob on Fri Oct 24, 2014 7:58 pm, edited 1 time in total.
User avatar
SnowyOwl47
Posts: 148
Joined: Fri Sep 12, 2014 10:41 pm

Re: ~Advanced Scripting and Editor Help

Post by SnowyOwl47 »

@dancodan WOAH ok I see a ton of responses to this and your getting confused hmmmm well I see your problem.

With alcoves you have to say

Code: Select all

alcove_name.surface:addItem("water_flask")
Thats what you do I'm pretty sure.

And you never do anything like

Code: Select all

monster_name.monster:setMaxHealth"100"()
Whatever your setting adding or whatever should be inside the () always. Sometimes you would say

Code: Select all

monster_name:destroy() 
And nothing gets put in the ()
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: ~Advanced Scripting and Editor Help

Post by JohnWordsworth »

I'm going to add an additional line of code to the pile! (This one has actually been tested in the editor - so I can confirm it definitely works).

Code: Select all

mine_alcove_3.surface:addItem(spawn("water_flask").item);
So, from my testing, you need to add an "item component" to a surface. The item component has to belong to a game object that actually exists, so you can either link to one that's already in the game (and it will move to the surface) or you can spawn a new item and place it in the alcove (which I assume is what you want to do).

The above script will...

1. Spawn a new water flask with the bit of code: spawn("water_flask").
2. Take the item component of that water flask using .item.
3. Get the surface component of the mine alcove and add the item component of the flask to the surface component of the alcove.

Sounds a bit convoluted, but it just requires understanding that a "component" is like like a "part" of a game object and you need to use the components for a lot of things now instead of just simple game components.
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
Post Reply