Page 1 of 1
Spider hatching from broken eggs, help?
Posted: Thu Jan 24, 2013 1:51 pm
by wolfee
I'm new at modding, first try actually, so sorry if I'm being an idiot. I'm following along the how-to for spawning spiders when you break their eggs and I just keep getting errors: (This was added to objects.lua and saved)
======================================
cloneObject{
name = "spider_eggs_hatching",
baseObject = "spider_eggs",
onDie = function(object)
eggScript.breakEggs(object.level, object.x, object.y)
end,
}
=====================================
I placed a few spider_eggs_hatching entities on the map and I started working on the first one. I added a script entity to the same spot, and set the ID to eggscript. Then within that entity I add:
==============================
function breakEggs(level, x, y)
local facing = (party.facing + 2)%4
spawn("spider", level, x, y, facing)
end
=================================
This is what I'm getting:
function breakEggs(1, 4, 6) <name> or '...' expected near '1'
local facing = (party.facing + 2)%4
spawn("spider", 1, 4, 6, facing)
end
I've changed '1' to Level 1, Level1 and just 1 and I still get errors. I haven't made it down to the spawn entry but I expect I will need to put a number in for the "facing" value? Again, sorry if this is a stupid question, I'm sure it's something simple but I'm going in circles with my troubleshooting.
Re: Spider hatching from broken eggs, help?
Posted: Thu Jan 24, 2013 3:33 pm
by Grimfan
Hi,
If you want to spawn the spider write it like this:
function breakEggs()
local facing = (party.facing + 2)%4
spawn("spider", level, x, y, facing)
end
Delete the info in the first set of brackets (in every circumstance I know of the brackets after the function are always empty) and make sure you leave the facing as written, otherwise the spider's facing won't change when it's spawned (putting 0 will always make it face north, 1 east etc.)
Lua (and any programming language) can be a handful at the start. I'm in the early stages of learning it myself.
Also, when testing the spider eggs just hit the clear (CLR) symbol. It will get rid of the invalid spawn messages that pop up (until you spawn more invalid entities that is).

Re: Spider hatching from broken eggs, help?
Posted: Thu Jan 24, 2013 4:12 pm
by wolfee
Grimfan,
I used your change and I don't get an error when I try to save but when I test it, as soon as the spider eggs would break (you don't see them break), I crash to desktop. Tried it 3 times, same result.
Re: Spider hatching from broken eggs, help?
Posted: Thu Jan 24, 2013 4:26 pm
by Grimfan
Two things,
You need to call your script entity eggScript not the default script_entity_1 or whatever otherwise the hatching egg will try to call a function that doesn't exist and you need to put in the level and x and y coordinates, so if you were going to spawn the spider on the 1st level of your dungeon at coordinates 15, 14 you would write spawn("spider",1,15,14,facing).
Hope that helps.
Re: Spider hatching from broken eggs, help?
Posted: Thu Jan 24, 2013 4:29 pm
by Grimwold
unfortunately Grimfan's first changes are not correct... the function definition needs the variables in the brackets so that it can receive the location of the particular eggs that are being broken.
if you are following this tutorial (
http://www.grimrock.net/modding/how-to- ... ider-eggs/) then I'm not quite sure what is causing the errors in your case.
Re: Spider hatching from broken eggs, help?
Posted: Thu Jan 24, 2013 4:32 pm
by Grimwold
Note, you only need these two bits:
Code: Select all
cloneObject{
name = "spider_eggs_hatching",
baseObject = "spider_eggs",
onDie = function(object)
eggScript.breakEggs(object.level, object.x, object.y)
end,
}
Code: Select all
function breakEggs(level, x, y)
local facing = (party.facing + 2)%4
spawn("spider", level, x, y, facing)
end
The first in objects.lua and the second in a script entity called eggScript.
You don't need additional scripts for each egg that you place.. The combination of the two parts above means that all breakable eggs will work wherever you put them
Re: Spider hatching from broken eggs, help?
Posted: Thu Jan 24, 2013 4:46 pm
by Grimfan
This is why people like you and Xanathar are invaluable to us newbies Grimwold.
I now also realise why the info in the first set of brackets is needed, but when I tried this script myself I just plain forgot to include the info in brackets and it worked fine, but only for 1 egg in one location and only because I included the coordinates. I now see that the script is meant for hatching multiple eggs on every level of your dungeon, so the coordinates aren't meant to specified.
Sorry for leading you astray Woolfee, we're both new to this modding game.

Re: Spider hatching from broken eggs, help?
Posted: Thu Jan 24, 2013 5:41 pm
by wolfee
Grimwold wrote:Note, you only need these two bits:
Code: Select all
cloneObject{
name = "spider_eggs_hatching",
baseObject = "spider_eggs",
onDie = function(object)
eggScript.breakEggs(object.level, object.x, object.y)
end,
}
Code: Select all
function breakEggs(level, x, y)
local facing = (party.facing + 2)%4
spawn("spider", level, x, y, facing)
end
The first in objects.lua and the second in a script entity called eggScript.
You don't need additional scripts for each egg that you place.. The combination of the two parts above means that all breakable eggs will work wherever you put them
Ok, I have the exact same thing in objects.lua. That created "spider_eggs_hatching" right below "spider_eggs".
I select "spider_eggs_hatching" and place it. Then I place a "script entity" right on top of the "spider_eggs_hatching" icon.
The 'Name' is called 'script_entity' and I gave it the ID of 'eggScript'.
Below that, it has a position of x=4 and y=8 and then a 'facing' direction indicator.
Below that is an empty text area for the function.
I paste in the function shown above and for my first try I did this:
=========================================================================
function breakEggs(1, 4, 8) # I get this message ==> <name> or '...' expected near '1'
local facing = (party.facing + 2)%4
spawn("spider", 1, 4, 8, facing)
end
=======================================================================
My second try, I left the function breakEggs(Level, x, y) as-is and I didn't get an error. Tested it out and sure enough I got attacked by a spider!!
Thank you so much for your help! The problem that made everything else snowball was I named the script_entity eggscript instead of eggScript the first time, once I saw that, I just had to realize the funtion was just showing the format and wasn't asking for input. Thanks!
Re: Spider hatching from broken eggs, help?
Posted: Thu Jan 24, 2013 6:15 pm
by wolfee
Wow, just realized what you were saying. I took specific coordinates out and voila, the dang spiders are popping out of every egg sack.