Page 1 of 19

Wagtunes' Modding Questions

Posted: Wed Apr 28, 2021 2:40 pm
by wagtunes
I haven't been modding for a while. Finally got back to it and am finding I am really rusty.

However, this particular problem, which should be a simple script, has me completely baffled as to why it crashes only under certain conditions.

Here is the script and here's what's happening.

Code: Select all

function checkAlcoveForItems()
   -- change these variables to match your alcove's ID and the item you want to test for
   local itemName1 = "blue_gem"
   local alcoveID1 = temple_alcove_5
   local itemName2 = "frostbite_necklace"
   local alcoveID2 = temple_alcove_6
   counter = 0
   
   -- iterate through all the contained items on alcove, checking for a matching name
   for i in alcoveID1:containedItems() do
      if i.name == itemName1 then
         itemFound1()
             
      end
   end
for i in alcoveID2:containedItems() do
      if i.name == itemName2 then
         itemFound2()
             
      end
   end
end

-- run this script _once for each item_ with a matching name
function itemFound1()
   counter = counter+1
   if counter == 2 then
   temple_door_iron_2:open()
end

function itemFound2()
   counter = counter+1
   if counter == 2 then
   temple_door_iron_2:open()
end

-- run this script _once for each item_ without a matching name

end
end
If I test this with all possibilities, this is what's happening.

1. If I put the items in the correct alcove, script works perfectly. Door opens.

2. If I put the items in the wrong alcoves, script works perfectly. Door stays closed.

Here is where things get wonky.

3. If I, after putting the items in the wrong alcove, remove them and then place the correct item in alcove_5, I get a script crash that reads.

'attempt to call global 'itemfound2' (a nil value) x

Why? Totally stumped.

Re: Useful scripts repository

Posted: Wed Apr 28, 2021 8:46 pm
by minmay
You aren't defining your itemFound2 function until itemFound1 is called, so if you try to call itemFound2 before itemFound1 you'll get that error. Just move your definition for itemFound2 outside of the body of itemFound1.

Re: Useful scripts repository

Posted: Wed Apr 28, 2021 9:00 pm
by wagtunes
minmay wrote: Wed Apr 28, 2021 8:46 pm You aren't defining your itemFound2 function until itemFound1 is called, so if you try to call itemFound2 before itemFound1 you'll get that error. Just move your definition for itemFound2 outside of the body of itemFound1.
Ah, I see it. Missing end statement for the "for" loop . Anyway, I reprogrammed the whole thing eliminating the functions altogether and just did straight logic. It's not pretty but it works because there's nothing to call.

Thanks for pointing out the problem. I really am rusty.

Re: Useful scripts repository

Posted: Mon May 03, 2021 2:41 pm
by wagtunes
Okay, now that I've got the basics of modeling down, I'm trying to really dive into scripting beyond the basic stuff that I can already do. Looking at the scripting reference, here's the problem with this whole thing and why learning this without a more comprehensive reference is futile.

Let's take a very specific example.

Here's a line out of ORR2 by Spiderfighter regarding drinking the potion of umbral absolution, which you're really not supposed to do.

Code: Select all

champion:setCondition("diseased", 75)
			champion:setCondition("paralyzed", 100)
Now, if you go to the scripting reference and look up champion:setCondition, this is what you find.

Code: Select all

Champion:setCondition(name)
Wonderful. So what are the valid names? How is somebody supposed to know? Do you just guess?

Is there a more comprehensive reference somewhere or is this all just trial and error?

If it is, it's not the most efficient way to learn how to script for LoG.

Re: Useful scripts repository

Posted: Mon May 03, 2021 2:52 pm
by minmay
I think you're looking at the wrong scripting reference. The Grimrock 1 scripting reference has this description for Champion:setCondition():
Champion:setCondition(condition, value)
Sets the value of a condition. The interpretation of value depends on the condition but it corresponds roughly to the number of seconds that the condition should last. The condition must be one of the following: “poison”, “diseased”, “paralyzed”, “haste”, “rage”, “fire_shield”, “shock_shield”, “poison_shield”, “frost_shield”, “invisibility”.
The Grimrock 2 scripting reference does lack descriptions for most of the functions, although a lot of the more confusing functions do have unofficial descriptions here. But since you're making a mod for Grimrock 1 you don't need to worry about that.

Re: Useful scripts repository

Posted: Mon May 03, 2021 3:02 pm
by wagtunes
minmay wrote: Mon May 03, 2021 2:52 pm I think you're looking at the wrong scripting reference. The Grimrock 1 scripting reference has this description for Champion:setCondition():
Champion:setCondition(condition, value)
Sets the value of a condition. The interpretation of value depends on the condition but it corresponds roughly to the number of seconds that the condition should last. The condition must be one of the following: “poison”, “diseased”, “paralyzed”, “haste”, “rage”, “fire_shield”, “shock_shield”, “poison_shield”, “frost_shield”, “invisibility”.
The Grimrock 2 scripting reference does lack descriptions for most of the functions, although a lot of the more confusing functions do have unofficial descriptions here. But since you're making a mod for Grimrock 1 you don't need to worry about that.
I'm looking at his page

http://www.grimrock.net/modding/scripting-reference/

I didn't know there was another one.

Re: Useful scripts repository

Posted: Mon May 03, 2021 3:11 pm
by wagtunes
I also noticed that the page you linked to is not complete. There are a number of commands on the other page that are not listed.

So again, without a complete reference, trying to script for this game becomes quite inefficient.

Re: Useful scripts repository

Posted: Mon May 03, 2021 4:52 pm
by Isaac
Grimrock 1 scripting reference: http://www.grimrock.net/modding_log1/sc ... reference/

Grimrock 2 scripting has several [major] differences that tend to make LoG1 scripts incompatible with it—usually, but not always.

_________________

Also: ORRR2 makes use of a user scripting framework; it supports script/features & function calls not in the base game.

https://sites.google.com/site/jkosgrimrock2/home

Re: Useful scripts repository

Posted: Mon May 03, 2021 7:27 pm
by wagtunes
Isaac wrote: Mon May 03, 2021 4:52 pm Grimrock 1 scripting reference: http://www.grimrock.net/modding_log1/sc ... reference/

Grimrock 2 scripting has several [major] differences that tend to make LoG1 scripts incompatible with it—usually, but not always.

_________________

Also: ORRR2 makes use of a user scripting framework; it supports script/features & function calls not in the base game.

https://sites.google.com/site/jkosgrimrock2/home
Again, compare this page to the page I linked to. This page is far from complete. There are numerous commands not listed.

The question remains, for LoG 1, how do you script for a program without a complete reference guide?

Re: Useful scripts repository

Posted: Mon May 03, 2021 8:27 pm
by Isaac
They never finished either guide. People took the executable apart, and guessed the rest; sometimes Petri would give advice, other times even implement requests. 8-)

*Glögg Sessions