Scriptig question on alcoves.

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
Ryeath_Greystalk
Posts: 366
Joined: Tue Jan 15, 2013 3:26 am
Location: Oregon

Scriptig question on alcoves.

Post by Ryeath_Greystalk » Wed Jan 23, 2013 7:06 am

I did my first attempt at scripting (not a programmer here, other than basic about 20 years ago, so it's very simple)

I used the scroll alcove script from the modding tutorial to put a scroll in an alcove.
local message = spawn("scroll")
message:setScrollText("The healing properties\nof the\ntarbead plant")
ScienceAlcove1:addItem(message)

Then I made a single cell room with a note explaining how to make health potions and a deactivated teleporter.
Then I connected the alcove to turn on the teleporter when the player picks up the scroll and it puts the note on the floor in front of the player,

and here comes my script
function dropnote()
hudPrint("as you cafefully open the scroll, a note drops to the floor in front of you.")
end
(thanks to Komags video tutorial)

So I have a few (3) questions hopefully someone can answer in a simple fashion. (at this point I should explain I am making a library in my dungeon with a bunch of scroll alcoves)
1. Can the dropnote script be joined with the scroll alcove script,
2. I'm starting to gain an understanding of the alcove script, first line creates the scroll, second tells it what to put on it, and the last line where it goes. What confuses me is why they all say message, instead of message1, message2 etc.
3. I'm using a separate script entity for each alcove (30+), so my map is really cluttered. I was thinking it could probably populate the alcoves with one script entity using a loop, maybe I'm wrong. Something like,

function FillAlcoves()
for n=1 to NumberofAlcoves
local message = spawn("scroll")
message:setScrollText(here I would need some kind of file or array I think)
LibraryAlcove(n):addItem(message)
next n
end

is that something doable?

Thanks

User avatar
Komag
Posts: 3637
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Scriptig question on alcoves.

Post by Komag » Wed Jan 23, 2013 12:21 pm

Good questions!

You could put all the functions in your entire dungeon in one script entity and put that entity anywhere you wanted on any level. The only time script entity location matters (IIRC) is when you use the "self" code, which refers to the entity, such as self.x, self.y, self.level, etc. I've never used that personally, but I see how it might be useful, such as spawning a piece of food at self.x, self.y, and if you want to move things around you just move the script entity instead of having to edit the coordinates. But I prefer to place my script entities out of the dungeon hallways or rooms, always off to the side somewhere, that's just my personal preference.

So to combine your first two pieces of script code you could just put them in a single script entity called textScript

Code: Select all

local message = spawn("scroll")
message:setScrollText("The healing properties\nof the\ntarbead plant")
ScienceAlcove1:addItem(message)

function dropnote()
hudPrint("as you cafefully open the scroll, a note drops to the floor in front of you.")
end
A few things going on in that script:
local message = spawn("scroll")
this means you are declaring a local variable called 'message', and you are also defining it at this time as 'spawn("scroll")'. So anytime for the rest of the script (but not outside the script, since it's just local) you use 'message' it will basically replace that with 'spawn("scroll)' (it's almost just like a replace, but not quite).
So you could leave that line out (and the next) and just put:

Code: Select all

ScienceAlcove1:addItem(spawn("scroll"):setScrollText("The healing properties\nof the\ntarbead plant"))
that's how I personally do all my scrolls and notes. Also I use multi-line text code if there are multiple lines, like this:

Code: Select all

ScienceAlcove1:addItem(spawn("scroll"):setScrollText([[
The healing properties
of the
tarbead plant
]]))
I honestly wouldn't know how to code filling the text of multiple scrolls all at once, but its probably doable in some way. But since you don't need separate script entities for each one but are only trying to clean up the clutter, then you can just use one or a few and have multiple scrolls in each.

BTW, if code is not within a function then it just gets run right at map start
Finished Dungeons - complete mods to play

Ryeath_Greystalk
Posts: 366
Joined: Tue Jan 15, 2013 3:26 am
Location: Oregon

Re: Scriptig question on alcoves.

Post by Ryeath_Greystalk » Wed Jan 23, 2013 4:02 pm

Thanks for the explanation Komag.

I didn't realize message was a variable, that clears things up.

And thanks for the idea of putting them all on one script, didn't know I could do that. That really cleaned things up, although for clarity I did one script for each library section.

And I had to learn the hardway about put the hudPrint in a function. I did it without one first and it came up right away, just as you said.

User avatar
msyblade
Posts: 792
Joined: Fri Oct 12, 2012 4:40 am
Location: New Mexico, USA
Contact:

Re: Scriptig question on alcoves.

Post by msyblade » Wed Jan 23, 2013 4:16 pm

Once again, Komag brings a complete and well thought out explanation. Hail the helpful one!
Currently conspiring with many modders on the "Legends of the Northern Realms"project.

"You have been captured by a psychopathic diety who needs a new plaything to torture."
Hotel Hades

User avatar
crisman
Posts: 305
Joined: Sat Sep 22, 2012 9:23 pm
Location: Italy

Re: Scriptig question on alcoves.

Post by crisman » Wed Jan 23, 2013 6:23 pm

For adding all of your scrolls in all your alcoves in one script, I did something like this:
First of all, let's say your alcoves are named like alcove1, alcove2, alcove3, ..., alcove11, and so on. For this example I will use 3 alcoves.

Code: Select all

function addScroll()
         local texts = {
               "Hello, this is the first message",
               "And this is the second one.",
               "I think this is number3!".
               }
            
               
         for i = 1, #texts do
             findEntity("alcove"..i):addItem((spawn("scroll"):setScrollText(texts[i])))
         end
end
In the array texts, you will put all of your messages, in order from the first to the last.
It should works. Since it's in a function, you will have to activate it with, for example, an invisible pressure plate, with "activate once" checked.
NOTE: if the alcoves in-game are less than your texts in the array, the script will not work properly and stops the editor with an error, so be careful about that ;)

User avatar
Komag
Posts: 3637
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Scriptig question on alcoves.

Post by Komag » Wed Jan 23, 2013 6:59 pm

Hmm, I wouldn't normally do anything like that, but maybe it could be useful for like a big library with tons of randomly placed books or scrolls, with a giant list of random texts to apply to them, all done automatically by code :)

The guy making the random dungeon creator could maybe work something like this in!
Finished Dungeons - complete mods to play

Post Reply