NEED HELP WITH MY ALCOVE SCRIPT!

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
User avatar
WaspUK1966
Posts: 135
Joined: Sat Aug 09, 2014 9:17 am

NEED HELP WITH MY ALCOVE SCRIPT!

Post by WaspUK1966 »

I have written a script for an alcove in my game that requires a skull to be placed there. When the skull is put in the alcove, the script increases the party`s experience points, and prints their names on screen to confirm this. It then also opens a closed door. At first glance, the code seemed to work well. My script is as follows:

function itemPuzzle()
for i in itemPuzzleAlcove:containedItems() do
if i.name == "skull" then
for i=1,4 do
party:getChampion(i):gainExp(250)
for n=1,4 do
local name1 = party:getChampion(n):getName()
hudPrint(""..name1..", has gained experience!")
end
templedooramulet:open()
playSound("secret")
end
else
templedooramulet:close()
end
end
end

I have two problems with this.
1) If I keep taking out and putting back the skull in the alcove, it keeps increasing the experience points. I need someway to terminate the script or stop it working once the skull has been placed into the alcove for the first time.
2) The script prints out all 4 of the party`s names as intended, but for some strange reason it prints out the first champions name again (so 5 names appear on screen). Anyway of fixing this?

Any help greatly appreciated. thanks.
User avatar
Isaac
Posts: 3179
Joined: Fri Mar 02, 2012 10:02 pm

Re: NEED HELP WITH MY ALCOVE SCRIPT!

Post by Isaac »

WaspUK1966 wrote:I have two problems with this.
1) If I keep taking out and putting back the skull in the alcove, it keeps increasing the experience points. I need someway to terminate the script or stop it working once the skull has been placed into the alcove for the first time.
2) The script prints out all 4 of the party`s names as intended, but for some strange reason it prints out the first champions name again (so 5 names appear on screen). Anyway of fixing this?

Any help greatly appreciated. thanks.
The hudPrint/getName loop is inside the gainExp loop, so the hudPrint loop runs four times; [that is, it runs the complete "N" loop code four times ~~and does this four times during the outer "I" loop].

For the alcove problem, the easiest way is to destroy the alcove in the script, and spawn a replacement.
hudPrint(""..name1..", has gained experience!")
This is odd; unless you wanted a space to precede the name, but there is no space between the quotes.

*Also: You can use the 'Code' tag to post script in, and the browser will not format it, and allows a handy 'select all' link for those intending to copy the code to an editor. This is good for longer scripts.
Post Reply