Wagtunes' Modding Questions

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
Zo Kath Ra
Posts: 940
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Useful scripts repository

Post by Zo Kath Ra »

wagtunes wrote: Mon May 10, 2021 2:27 pm That's actually a very good point. You know, before I retired (yes, I'm old LOL) I used to be a programmer for a medical billing software company. I was quite good. But it's been a long time and I'm rusty. But the bigger problem is learning a new language when there isn't a full blown textbook to study. My C++ book was over 1,000 pages. The scripting for LoG seems to be very bare bones as far as reference materials. That's what's making this so difficult for me. Logic I know inside and out. But when you don't know what the commands are or what arguments they require, it makes coding a royal PITA. In short, it's like learning how to walk all over again. Challenging, but frustrating too.
Time to become good again 8-)

As for LoG1 scripting... you have distinguish between learning LUA and learning the LoG1 API / engine internals.
For leaning LUA, I'd recommend https://www.lua.org/pil/
User avatar
Zo Kath Ra
Posts: 940
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Useful scripts repository

Post by Zo Kath Ra »

Isaac wrote: Mon May 10, 2021 3:17 pm I like LoG1 better, but prefer LoG2 scripting. The LoG2 engine can be used to make LoG1 style adventures.
I prefer everything about LoG2 :D
wagtunes
Posts: 316
Joined: Sun Feb 04, 2018 11:04 pm

Re: Useful scripts repository

Post by wagtunes »

Isaac wrote: Mon May 10, 2021 3:17 pm I like LoG1 better, but prefer LoG2 scripting. The LoG2 engine can be used to make LoG1 style adventures.

*Though Petri has asked that no one remake LoG1 with it. :!:

ORRR2 could be ported to LoG2, and the scripting able to be greatly simplified to achieve the same result, as well as having the potential for more complex behavior. 8-)
I would so love it if somebody would do that. ORR2 is off the charts amazing. I never tire of it even if I know the entire dungeon by heart now.
wagtunes
Posts: 316
Joined: Sun Feb 04, 2018 11:04 pm

Re: Useful scripts repository

Post by wagtunes »

Zo Kath Ra wrote: Mon May 10, 2021 3:35 pm
wagtunes wrote: Mon May 10, 2021 2:27 pm That's actually a very good point. You know, before I retired (yes, I'm old LOL) I used to be a programmer for a medical billing software company. I was quite good. But it's been a long time and I'm rusty. But the bigger problem is learning a new language when there isn't a full blown textbook to study. My C++ book was over 1,000 pages. The scripting for LoG seems to be very bare bones as far as reference materials. That's what's making this so difficult for me. Logic I know inside and out. But when you don't know what the commands are or what arguments they require, it makes coding a royal PITA. In short, it's like learning how to walk all over again. Challenging, but frustrating too.
Time to become good again 8-)

As for LoG1 scripting... you have distinguish between learning LUA and learning the LoG1 API / engine internals.
For leaning LUA, I'd recommend https://www.lua.org/pil/
Well, it'll take time. Fortunately, this is an amazingly helpful community. Probably the best one I have ever encountered online and that's going back to 1997.
wagtunes
Posts: 316
Joined: Sun Feb 04, 2018 11:04 pm

Re: Useful scripts repository

Post by wagtunes »

Okay, I have this code that I created (with your help) to spawn an altar with an item.

Code: Select all

function spawnaltar()

spawn("altar",1,16,26,0,"ironkeyaltar"):addItem(spawn("iron_key"));
spawn("temple_ceiling_lamp",1,16,26,0)

end
I now want to spawn an altar with 2 items. I can't seem to figure out how to do it. I've tried adding another addItem and I've tried putting a comma after "iron_key" but neither works. Is it even possible to spawn an altar with more than one item?
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: Useful scripts repository

Post by Isaac »

Code: Select all

function spawnAltar(self)
	spawn("temple_ceiling_lamp",1,16,26,0)
	if not findEntity("ironkeyaltar") then
	
	--local altar = spawn("altar",1,16,26,0,"ironkeyaltar") --disabled, in order to use the alternate line below.
	
	  local altar = spawn("altar",self.level,self.x,self.y,self.facing,"ironkeyaltar") --this spawns the altar wherever you place the script_entity.	  Also returns the object to the local variable 'altar'.
	  		
			  altar:addItem(spawn("iron_key"))
			  altar:addItem(spawn("blueberry_pie"))
			  altar:addItem(spawn("boots_valor"))
			  altar:addItem(spawn("zhandul_orb"))
	  
		--optional item positioning

				for itm in altar:containedItems() do
				
					itm:setSubtileOffset(math.random()-.45, math.random()-.45) 	--randomized position
					
				end  
				
		--/optional item positioning
		
	end
end
spawnAltar(self)
Last edited by Isaac on Tue May 11, 2021 1:12 am, edited 1 time in total.
wagtunes
Posts: 316
Joined: Sun Feb 04, 2018 11:04 pm

Re: Useful scripts repository

Post by wagtunes »

Isaac wrote: Tue May 11, 2021 12:56 am

Code: Select all

function spawnAltar(self)
	spawn("temple_ceiling_lamp",1,16,26,0)
	if not findEntity("ironkeyaltar") then
	
	--local altar = spawn("altar",1,16,26,0,"ironkeyaltar") --disabled, in order to use the alternate line below.
	
	  local altar = spawn("altar",self.level,self.x,self.y,self.facing,"ironkeyaltar") --this spawns the altar wherever you place the script_entity.	  
	  		
			  altar:addItem(spawn("iron_key"))
			  altar:addItem(spawn("blueberry_pie"))
			  altar:addItem(spawn("boots_valor"))
			  altar:addItem(spawn("zhandul_orb"))
	  
		--optional item positioning

		  		--local itemCt = altar:getItemCount() * .1
		
				for itm in altar:containedItems() do
				
					itm:setSubtileOffset(math.random()-.45, math.random()-.45) 	--randomized position
					
				end  
				
		--/optional item positioning
		
	end
end
spawnAltar(self)
Okay, here's what's happening. I want this script to run when I insert a key into a lock. However, when I start the dungeon in the editor, the altar is already spawned before I insert the key. I even removed the connector from the script but the altar still spawns as soon as I start the dungeon.

How does a script run automatically like that?
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: Useful scripts repository

Post by Isaac »

First, I just erased an unused line that was overlooked when I posted. Update to the most recent script.

The way it auto-runs is that the script calls its own function when loaded; see the last line.

Delete (or comment out) the line at the end that calls the function, and your connector will work as expected.

You can delete either one of these lines, as best suits:
You only need one.

Code: Select all

local altar = spawn("altar",1,16,26,0,"ironkeyaltar") 

local altar = spawn("altar",self.level,self.x,self.y,self.facing,"ironkeyaltar")
The call to findEntity is to ensure that the object "ironkeyaltar" does not exist before using the name for a new object. It's good to always check first, as the game will crash if this situation occurs.
wagtunes
Posts: 316
Joined: Sun Feb 04, 2018 11:04 pm

Re: Useful scripts repository

Post by wagtunes »

Okay, I took the basic code you gave me for adding multiple items and came up with this.

Code: Select all

function spawnaltar()

local altar = spawn("altar",1,10,4,0,"ironkeyaltar")

altar:addItem(spawn("iron_key"))
altar:addItem(spawn("blueberry_pie"))
altar:addItem(spawn("boots_valor"))
altar:addItem(spawn("zhandul_orb"))

end
I'll change the items later. This simple script kept the script from running at startup. Still not sure why that's happening but this fixed the problem. So basically, you assign a variable to altar and then use that variable to spawn an item line by line.

Thanks.
wagtunes
Posts: 316
Joined: Sun Feb 04, 2018 11:04 pm

Re: Useful scripts repository

Post by wagtunes »

Isaac wrote: Tue May 11, 2021 1:13 am First, I just erased an unused line that was overlooked when I posted. Update to the most recent script.

The way it auto-runs is that the script calls its own function when loaded; see the last line.

Delete (or comment out) the line at the end that calls the function, and your connector will work as expected.

You can delete either one of these lines, as best suits:
You only need one.

Code: Select all

local altar = spawn("altar",1,16,26,0,"ironkeyaltar") 

local altar = spawn("altar",self.level,self.x,self.y,self.facing,"ironkeyaltar")
The call to findEntity is to ensure that the object "ironkeyaltar" does not exist before using the name for a new object. It's good to always check first, as the game will crash if this situation occurs.
Ah okay. I'll tidy things up when I create with the actual items I need.

Thanks again.
Post Reply