Ask a simple question, get a simple answer

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
THOM
Posts: 1274
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

yes, mimay, that's the part I understood.

but I thought, to check, if a monster exist, I ask, if it's alive.

thanks to AndakRainor I know 1) how to do it right, 2) that a monster CAN exist while being not alive.
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: Ask a simple question, get a simple answer

Post by Azel »

AndakRainor wrote:

Code: Select all

if ratling1_1 ~= nil and ratling1_1.monster:isAlive() then ... end
If ratling1_1 proves to be null, then the second part of that condition will generate an error.

Here is a safer version of your code:

Code: Select all

if ratling1_1 != nil then
	if ratling1_1.monster:isAlive() then
		-- Do Something
	end
end
How I would likely write it:

Code: Select all

local ratling = findEntity("ratling1_1");

if ratling then
	if ratling.monster:isAlive() then
		-- Do Something
	end
end
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Ask a simple question, get a simple answer

Post by AndakRainor »

In lua as in most other languages the "and" operator does not evaluate the second operand when the first is false
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: Ask a simple question, get a simple answer

Post by Azel »

Ah you're right, I just tested it. Sorry, I don't trust LUA that much lol :o
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Ask a simple question, get a simple answer

Post by AndakRainor »

I have defined a clickable "wall". When you click on it it opens or closes. But when it is opened and an item is in mouse selection, I would like to allow the player to throw the mouse item instead of closing the wall... How could I do that ?
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

AndakRainor wrote:I have defined a clickable "wall". When you click on it it opens or closes. But when it is opened and an item is in mouse selection, I would like to allow the player to throw the mouse item instead of closing the wall... How could I do that ?

Code: Select all

onClick = function(self) if getMouseItem() then return false else self.go.door:toggle() end end,
SpoilerShow
defineObject{
name = "dungeon_click_secret_door",
baseObject = "base_secret_door",
components = {
{
class = "Model",
model = "assets/models/env/dungeon_secret_door.fbx",
staticShadow = true,
},
{
class = "Clickable",
offset = vec(0, 1.5, 0),
size = vec(1.2, 0.8, 0.2),
frontFacing = true,
onClick = function(self) if getMouseItem() then return false else self.go.door:toggle() end end,
},
},
}
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Ask a simple question, get a simple answer

Post by AndakRainor »

Thanks Isaac, that is also what I thought. But when I test this, it prevents the wall from closing, which is good, but the item is not thrown. So my problem is, whatever I tried so far, this wall, opened or not, prevents throwing items from the mouse selection because of the clickable component standing in the way.
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Ask a simple question, get a simple answer

Post by akroma222 »

Hey All!!
Where would I find the icon atlas that has all the tiny Condition icons???
Thanks
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

AndakRainor wrote:Thanks Isaac, that is also what I thought. But when I test this, it prevents the wall from closing, which is good, but the item is not thrown. So my problem is, whatever I tried so far, this wall, opened or not, prevents throwing items from the mouse selection because of the clickable component standing in the way.
Hmmm...
When I test this, the wall opens or closes ~unless there is an object on the mouse cursor; in which case the door ignores the click, and depending on the hight of the cursor, the object is either placed on the floor, or thrown. :?

Is there a notable between your defined door, and the one in my post? (in the spoiler tag)

Edit: Aha... It seems to involve the clickable region; as can be seen with debugDraw = true, in the clickable component.
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Ask a simple question, get a simple answer

Post by AndakRainor »

The offset of the clickable component is the same, but not its size. I will try different sizes tonight and see if I get a better result.
Post Reply