Calling on a spawned item.

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!
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Calling on a spawned item.

Post 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.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Calling on a spawned item.

Post 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).
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Re: Calling on a spawned item.

Post 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?
User avatar
Dr.Disaster
Posts: 2876
Joined: Wed Aug 15, 2012 11:48 am

Re: Calling on a spawned item.

Post 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.
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Re: Calling on a spawned item.

Post 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 Image
alois
Posts: 112
Joined: Mon Feb 18, 2013 7:29 am

Re: Calling on a spawned item.

Post 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 :)
User avatar
Dr.Disaster
Posts: 2876
Joined: Wed Aug 15, 2012 11:48 am

Re: Calling on a spawned item.

Post 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 ;)
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Re: Calling on a spawned item.

Post 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
:D and now the damn door opens.. (I was having trouble getting it to open i forgot to give it the .door afterthe name duhh..)
User avatar
Zo Kath Ra
Posts: 944
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Calling on a spawned item.

Post by Zo Kath Ra »

You spawn a dagger that falls to the ground and then immediately disappears?
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Re: Calling on a spawned item.

Post 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.
Post Reply