Page 3 of 4

Re: ~Advanced Scripting and Editor Help

Posted: Fri Oct 24, 2014 10:39 am
by Mysterious
Now this is where Akroma takes over and blows us all away - Rem his last Mod? :)

Re: ~Advanced Scripting and Editor Help

Posted: Fri Oct 24, 2014 10:41 am
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

Re: ~Advanced Scripting and Editor Help

Posted: Fri Oct 24, 2014 10:47 am
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 :)

Re: ~Advanced Scripting and Editor Help

Posted: Fri Oct 24, 2014 11:42 am
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

Re: ~Advanced Scripting and Editor Help

Posted: Fri Oct 24, 2014 12:15 pm
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

Re: ~Advanced Scripting and Editor Help

Posted: Fri Oct 24, 2014 12:24 pm
by Komag
use " ", such as "water_flask"

Re: ~Advanced Scripting and Editor Help

Posted: Fri Oct 24, 2014 3:17 pm
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 ?

Re: ~Advanced Scripting and Editor Help

Posted: Fri Oct 24, 2014 3:29 pm
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.

Re: ~Advanced Scripting and Editor Help

Posted: Fri Oct 24, 2014 4:50 pm
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 ()

Re: ~Advanced Scripting and Editor Help

Posted: Fri Oct 24, 2014 7:56 pm
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.