Page 1 of 2
Calling on a spawned item.
Posted: Wed Jun 10, 2015 7:48 pm
by Emera Nova
So for testing purposes I'm attempting to get a dagger to be spawned from a spawner and have it land on a pressure plate. When it does a script is run to see if that dagger is present if it is open a door.
Problem is I don't know what the name of the newly spawned dagger is.
Code: Select all
function destroyObject()
if findEntity("dagger_") ~= nil then
dungeon_door_wooden_11:open()
end
end
This is what I currently have running to test this out. I'm trying to get this idea to work so that I can move on to what I'll be implementing in on my next dungeon.
Re: Calling on a spawned item.
Posted: Wed Jun 10, 2015 8:16 pm
by minmay
The "spawn" global function returns the object spawned. Consider using that instead. If you insist on using a spawner object, you will have to use Map:entitiesAt() on the spawner's square to find the item after it's spawned (use the spawner's onActivate connector).
Re: Calling on a spawned item.
Posted: Wed Jun 10, 2015 11:14 pm
by Emera Nova
So I tried to put in this
function spawn()
spawn(dagger,7,12,18,2,1,Dagger)
end
And when I run that it throws up a giant error. I'm guessing my format on that is still incorrect ye?
Re: Calling on a spawned item.
Posted: Wed Jun 10, 2015 11:28 pm
by Dr.Disaster
The object to spawn needs to be quoted like: spawn("dagger",7,12,18,2,1)
If the last and optional id parameter needs to be quoted should be easy to find out.
At least you need to make sure it's id is truely unique so using just "Dagger" might not do.
Re: Calling on a spawned item.
Posted: Thu Jun 11, 2015 4:19 pm
by Emera Nova
So I have this code in
Code: Select all
function spawn()
spawn("dagger",7,12,18,2,1,powerdagger)
end
when I went and ran it this happened

Re: Calling on a spawned item.
Posted: Thu Jun 11, 2015 4:25 pm
by alois
First of all, it should be:
Code: Select all
function spawn()
spawn("dagger",7,12,18,2,1,"powerdagger")
end
Then, if you call the function "spawn()", you are re-defining the grimrock "spawn" function; therefore, what happens when you call your function "spawn()" is that the function calls itself and then calls itself, and then calls itself..., and not the one you want; I suggest you change the function to
Code: Select all
function spawnDagger()
spawn("dagger",7,12,18,2,1,"powerdagger")
end
Alois

Re: Calling on a spawned item.
Posted: Thu Jun 11, 2015 4:32 pm
by Dr.Disaster
Aye, it's an infinite re-definition loop; should have seen that too but i did not look at the function name.
At least we know the modified spawn call worked

Re: Calling on a spawned item.
Posted: Thu Jun 11, 2015 4:51 pm
by Emera Nova
Yay xD that fixed the problem..
Now I just have to see if I can finds my notes and figure out why I needed to figure out how to do that.. xD
For now at least I can spawn an item in at a location and then call on it.'
I step on a pressure plate and it triggers a script with this on it.
Code: Select all
function spawnDagger()
spawn("dagger",7,12,18,2,1,"powerdagger")
end
The dagger falls and lands on floor trigger and causes this to happen.
Code: Select all
function checkObject()
if findEntity("powerdagger") ~= nil then
powerdagger:destroy()
dungeon_door_wooden_11.door:open()
end
end

and now the damn door opens.. (I was having trouble getting it to open i forgot to give it the .door afterthe name duhh..)
Re: Calling on a spawned item.
Posted: Thu Jun 11, 2015 5:21 pm
by Zo Kath Ra
You spawn a dagger that falls to the ground and then immediately disappears?
Re: Calling on a spawned item.
Posted: Thu Jun 11, 2015 5:28 pm
by Emera Nova
Yes, I was just testing out how to get stuff to spawn in so I can use it for later stuff. I also wanted to test out calling on the stuff that I spawned since Im working with a dagger I just had it disappear aftwards to open the door. Could be anything really.