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
st1nger
Posts: 19
Joined: Wed May 29, 2013 8:44 pm
Location: Germany

Re: Ask a simple question, get a simple answer

Post by st1nger »

Eleven Warrior wrote:Hi all. I have forgot how to do this (code below) When floor_trigger_3 is down something happens. If floor_trigger_3 is up something happens. The error I am getting is with the (isDown) bit. Please help I know it's easy imam sure thxs :)

Code: Select all

function checkLevers()

    if floor_trigger_3:isDown() then
hudPrint("hello")
	else if floor_trigger_3:isUp() then
hudPrint("bye")
 
end
end
end

hi :)

I have corrected the code
this works:

Code: Select all

function checkLevers()
	if floor_trigger_3.floortrigger:isActivated() then
		hudPrint("hello")
	else floor_trigger_3.floortrigger:isDeactivated()
		hudPrint("bye")
    end
end

floortrigger has only 2 stages, you dont need to check for isDeactivated() when you check for isActivated() one line above.

this works also fine:

Code: Select all

function checkLevers()
	if floor_trigger_3.floortrigger:isActivated() then
		hudPrint("hello")
	else
		hudPrint("bye")
    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 »

hi! When I use

Code: Select all

o:setPosition(o.x, o.y, o.facing, ground, o.level)
on a GameObject o with an obstacle component, the previous position of the object is still considered blocked by the game. Why ? What should I do to avoid this strange behavior ?
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:hi! When I use

Code: Select all

o:setPosition(o.x, o.y, o.facing, ground, o.level)
on a GameObject o with an obstacle component, the previous position of the object is still considered blocked by the game. Why ? What should I do to avoid this strange behavior ?
Any object? That did not happen when I tried it in the editor with an altar.
Nor with a barrel crate blockage.
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Was the object a pushable block by any chance?
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
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 »

It does happen with pushable_blocks and no floor. [With or without.]
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 »

Yes it also has a PushableBlock component and DynamicObstacle component... Is it hopeless ?

Code: Select all

defineObject{
	name = "ice_cube",
	baseObject = "base_obstacle",
	components = {
		{
			class = "Model",
			model = "assets/models/env/pushable_block_01.fbx",
         material = "ice_cube",
			offset = vec(0, 0.05, 0),
		},
		{
			class = "Light",
			offset = vec(0, 1.75, 0),
			range = 6,
			color = vec(0.2, 0.5, 1),
			brightness = 20,
			castShadow = false,
			fillLight = true,
		},
		{
			class = "Particle",
			particleSystem = "force_field",
		},
		{
			class = "Sound",
			sound = "force_field_ambient",
		},
		{
			class = "ProjectileCollider",
		},
		{
			class = "Obstacle",
			hitSound = "terracotta_jar_hit",
			hitEffect = "hit_terracotta_jar",
		},
		{
			class = "Health",
			health = 50,
         immunities = { "cold" },
		},
		{
			class = "DynamicObstacle",
		},
      userData,
      {
         class = "Timer",
         timerInterval = 0.001,
         triggerOnStart = true,
         onActivate = function(self)
           self.go.data:set("vz", spells_functions.script.checkUnder(self.go.id, self.go.data:get("vz") or 0, Time.deltaTime()))
         end,
      },
		{
			class = "PushableBlock",
		},
		{
			class = "Clickable",
			name = "clickNorth",
			offset = vec(0, 1.15, 1.2),
			size = vec(1.2, 1.2, 0.1),
			maxDistance = 1,
			--debugDraw = true,
			onClick = function(self)
				hudPrint("push north!")
            --self.go.gravity:setFallingSpeed(1)
				if party.facing == (self.go.facing+2) % 4 then
              self.go.pushableblock:activate()
              if ice_push_source then ice_push_source:destroy() end
              spawn("ice_pushable_block_floor", self.go.level, self.go.x, self.go.y, self.go.facing, self.go.elevation, ice_push_source).controller:activate()
              local dx,dy = getForward(party.facing)
              if ice_push_target then ice_push_target:destroy() end
              spawn("ice_pushable_block_floor", self.go.level, self.go.x+dx, self.go.y+dy, self.go.facing, self.go.elevation, ice_push_target).controller:activate()
	           self.go.pushableblock:push(party.facing)
				end
			end,
		},
		{
			class = "Clickable",
			name = "clickEast",
			offset = vec(1.2, 1.15, 0),
			size = vec(0.1, 1.2, 1.2),
			maxDistance = 1,
			--debugDraw = true,
			onClick = function(self)
				hudPrint("push east!")
				if party.facing == (self.go.facing+3) % 4 then
              self.go.pushableblock:activate()
              if ice_push_source then ice_push_source:destroy() end
              spawn("ice_pushable_block_floor", self.go.level, self.go.x, self.go.y, self.go.facing, self.go.elevation, ice_push_source).controller:activate()
              local dx,dy = getForward(party.facing)
              if ice_push_target then ice_push_target:destroy() end
              spawn("ice_pushable_block_floor", self.go.level, self.go.x+dx, self.go.y+dy, self.go.facing, self.go.elevation, ice_push_target).controller:activate()
              self.go.pushableblock:push(party.facing)
				end
			end,
		},
		{
			class = "Clickable",
			name = "clickSouth",
			offset = vec(0, 1.15, -1.2),
			size = vec(1.2, 1.2, 0.1),
			maxDistance = 1,
			--debugDraw = true,
			onClick = function(self)
				hudPrint("push south!")
				if party.facing == self.go.facing then
              self.go.pushableblock:activate()
              if ice_push_source then ice_push_source:destroy() end
              spawn("ice_pushable_block_floor", self.go.level, self.go.x, self.go.y, self.go.facing, self.go.elevation, ice_push_source).controller:activate()
              local dx,dy = getForward(party.facing)
              if ice_push_target then ice_push_target:destroy() end
              spawn("ice_pushable_block_floor", self.go.level, self.go.x+dx, self.go.y+dy, self.go.facing, self.go.elevation, ice_push_target).controller:activate()
              self.go.pushableblock:push(party.facing)
				end
			end,
		},
		{
			class = "Clickable",
			name = "clickWest",
			offset = vec(-1.2, 1.15, 0),
			size = vec(0.1, 1.2, 1.2),
			maxDistance = 1,
			--debugDraw = true,
			onClick = function(self)
				hudPrint("push west!")
            if party.facing == (self.go.facing+1) % 4 then
              self.go.pushableblock:activate()
              if ice_push_source then ice_push_source:destroy() end
              spawn("ice_pushable_block_floor", self.go.level, self.go.x, self.go.y, self.go.facing, self.go.elevation, ice_push_source).controller:activate()
              local dx,dy = getForward(party.facing)
              if ice_push_target then ice_push_target:destroy() end
              spawn("ice_pushable_block_floor", self.go.level, self.go.x+dx, self.go.y+dy, self.go.facing, self.go.elevation, ice_push_target).controller:activate()
              self.go.pushableblock:push(party.facing)
				end
			end,
		},
	},
	placement = "floor",
	editorIcon = 272,
	tags = { "obstacle" },
}

defineObject{
	name = "ice_pushable_block_floor",
	baseObject = "base_floor_decoration",
	components = {
		{
			class = "PushableBlockFloor",
			name = "controller",
		},
	},
	replacesFloor = false,
}
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 »

Just remove the dynamicobstacle compontent, move the object, then create the dynamicobstacle component again.
(Disabling it is not sufficient.)
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 just found out that DynamicObstacle is the culprit ! This component is needed to spawn the object (don't know why but without it an error is raised), but it can be disabled from the very start (enabled = false); it solves the problem and doesn't affect the other behaviors of the block !

PS: now I need to make sure a platform follows the top of this block so it can be walked over and it will finally be finished ! So much pain !
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 »

Isaac wrote:Just remove the dynamicobstacle compontent, move the object, then create the dynamicobstacle component again.
(Disabling it is not sufficient.)
Well, after testing it it seems the previous position is correctly released, and as an obstacle and a pushable block it still correctly moves. What would be missing without the destruction and creation you suggest ?
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:
Isaac wrote:Just remove the dynamicobstacle compontent, move the object, then create the dynamicobstacle component again.
(Disabling it is not sufficient.)
Well, after testing it it seems the previous position is correctly released, and as an obstacle and a pushable block it still correctly moves. What would be missing without the destruction and creation you suggest ?
If you do not remove the dynamicobstacle component, it blocks the original tile, but releases as soon as the block is pushed. If you disable it instead of removing it, the tile is freed ~until you enable it again. If you remove it, and create it again, it just works as one would expect (aside from the unexpected need for this kludge). I don't think that anything is or would be missing, but I'm not exactly sure what you mean.
Post Reply