General scripting issues and questions

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: General scripting issues and questions

Post by Isaac »

Two New Questions:

Would someone please explain or post an example of the use for 'entitiesAt' ?
What exactly does this function do? (Aside from what's hinted by the name. ;) )

And is what is the way to detect the calling object within the called script?
*Meaning if Button_1 (of several) triggers a script (that they all are connected to), how can the calling button ID be detected?
Batty
Posts: 509
Joined: Sun Apr 15, 2012 7:04 pm

Re: General scripting issues and questions

Post by Batty »

Isaac wrote:Two New Questions:

Would someone please explain or post an example of the use for 'entitiesAt' ?
What exactly does this function do? (Aside from what's hinted by the name. ;) )
Pick a square with stuff in it and run this script:

Code: Select all

for entity in entitiesAt(1, 17, 16) do
	print("entity is "..entity.name)
   if entity.name == "lurker_hood" then
		do this
	end
end
entitiesAt cycles through everything in the square (level, x, y) so you use it as an iterator in a loop and then you check all the items in that square for something.

Try this:

Code: Select all

for entity in allEntities(1) do
	print("entity is "..entity.name)
end
And it spits out everything in level 1, pretty cool and useful.
When trying to figure something out in a script, put a print line in to see what it's doing.
And is what is the way to detect the calling object within the called script?
*Meaning if Button_1 (of several) triggers a script (that they all are connected to), how can the calling button ID be detected?
I'd like to know this too!
Last edited by Batty on Wed Oct 03, 2012 5:12 am, edited 1 time in total.
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: General scripting issues and questions

Post by Isaac »

Batty wrote: entitiesAt cycles through everything in the square (level, x, y) so you use it as an iterator in a loop and then you check all the items in that square for something.
Image Thank you; that explains it perfectly.

About the calling function ID: I'd like to be able to script some mutually exclusive buttons that could share a common function, but that the function would need to know which one was pushed, and how many times.
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: General scripting issues and questions

Post by Komag »

petri says this about a new feature:
"- when a script function is triggered it receives the sender of the message as first argument, e.g.
when a button triggers function 'foo' in a script entity, the function receives the button object as its first argument"

Maybe that will help?
also, you could have each button decrement separate counters, and have the script check those counters
Finished Dungeons - complete mods to play
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: General scripting issues and questions

Post by Isaac »

Komag wrote:petri says this about a new feature:
"- when a script function is triggered it receives the sender of the message as first argument, e.g.
when a button triggers function 'foo' in a script entity, the function receives the button object as its first argument"

Maybe that will help?
I read about the change as soon as it was released. Very cool. 8-)
also, you could have each button decrement separate counters, and have the script check those counters
That's exactly what I did; and the script used the calling button as a condition. I used this to script the Potion puzzle from EOB/ level 4; the one where you find the small room with four doors, and inside is a spider, potion, and key.
SpoilerShow
The puzzle offers you one extra potion if you enter the room from each door, with the rest of them closed; each time you do, you get a potion ~for a total of four.
Another Script Question:
How does one access the contents of an alcove in a script; Is there an iterator for alcoves?
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: General scripting issues and questions

Post by Grimwold »

Isaac wrote:Another Script Question:
How does one access the contents of an alcove in a script; Is there an iterator for alcoves?
as discussed in this thread..
viewtopic.php?f=14&t=3083

alcoveID:containedItems()
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: General scripting issues and questions

Post by Isaac »

Thanks 8-)

----------------

I've got another, if any knows: Does the Grimrock editor support labels and...
SpoilerShow
goto :o
Batty
Posts: 509
Joined: Sun Apr 15, 2012 7:04 pm

Re: General scripting issues and questions

Post by Batty »

....
Last edited by Batty on Thu Jan 26, 2017 4:51 pm, edited 1 time in total.
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: General scripting issues and questions

Post by Isaac »

Batty wrote:goto reminds me of my Apple IIe :lol:
And reminds me of my TRS-80 and CoCo 1, 2 & 3. :roll:

_________________

Would someone else please try this code?

Code: Select all

function activate()
dungeon_alcove_1:addItem(spawn("dagger"))
end
I have an alcove in place with the ID "dungeon_alcove_1", and when I run this script... nothing seems to happen; no dagger appears in the alcove; or is that not the way adding items works?
Is there an error in this code?

Image
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: General scripting issues and questions

Post by petri »

Are you sure the function gets triggered?
Post Reply