Page 4 of 6
Re: General scripting issues and questions
Posted: Wed Oct 03, 2012 3:33 am
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?
Re: General scripting issues and questions
Posted: Wed Oct 03, 2012 3:56 am
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!
Re: General scripting issues and questions
Posted: Wed Oct 03, 2012 4:54 am
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.

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.
Re: General scripting issues and questions
Posted: Wed Oct 03, 2012 12:34 pm
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
Re: General scripting issues and questions
Posted: Wed Oct 03, 2012 1:38 pm
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.
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.
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?
Re: General scripting issues and questions
Posted: Wed Oct 03, 2012 5:17 pm
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()
Re: General scripting issues and questions
Posted: Thu Oct 04, 2012 2:13 am
by Isaac
Thanks
----------------
I've got another, if any knows: Does the Grimrock editor support labels and...
goto

Re: General scripting issues and questions
Posted: Thu Oct 04, 2012 2:16 am
by Batty
....
Re: General scripting issues and questions
Posted: Thu Oct 04, 2012 3:33 am
by Isaac
Batty wrote:goto reminds me of my Apple IIe

And reminds me of my TRS-80 and CoCo 1, 2 & 3.
_________________
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?

Re: General scripting issues and questions
Posted: Thu Oct 04, 2012 6:33 am
by petri
Are you sure the function gets triggered?