Page 207 of 400

Re: Ask a simple question, get a simple answer

Posted: Sat Aug 05, 2017 9:40 pm
by Isaac
The button asset has a dedicated disableSelf option in the editor properties.

....But it doesn't seem to work. :shock:

What you can do instead is the following:

Code: Select all

--Put this in a script_entity, and add a connection to it from any button that you wish disabled.
function disableButton(button)
	local count = button.go.button:getConnectorCount()
	for C = count, 1, -1 do
		local buttonId = findEntity(button.go.id)
		if buttonId then
			buttonId.button:removeConnector(buttonId.button:getConnector(1))
		end	
	end
end

Re: Ask a simple question, get a simple answer

Posted: Sun Aug 06, 2017 12:27 am
by Xardas
That's strange. I had the disableSelf option on true. I'm going to chrck that on another connection later.
Thanks for the script. That will make some things easier. :D

Re: Ask a simple question, get a simple answer

Posted: Sun Aug 06, 2017 7:05 am
by minmay
Isaac wrote:The button asset has a dedicated disableSelf option in the editor properties.

....But it doesn't seem to work. :shock:

What you can do instead is the following:

Code: Select all

--Put this in a script_entity, and add a connection to it from any button that you wish disabled.
function disableButton(button)
	local count = button.go.button:getConnectorCount()
	for C = count, 1, -1 do
		local buttonId = findEntity(button.go.id)
		if buttonId then
			buttonId.button:removeConnector(buttonId.button:getConnector(1))
		end	
	end
end
This has come up before. It's easier to do this (not to mention much more correct, since it allows enabling the button again):

Code: Select all

defineObject{
	name = "wall_button",
	baseObject = "wall_button",
	components = {
		{
			class = "Button",
			sound = "button",
			onActivate = function(self)
				return self:isEnabled()
			end,
		},
	}
}

Re: Ask a simple question, get a simple answer

Posted: Sun Aug 06, 2017 10:26 am
by Isaac
One certainly can... but the above script was quickly written specifically to not rely on enabled/disabled. I like your conventional method better.

I wonder how it happened that a button's disableSelf setting doesn't disable the button?

Re: Ask a simple question, get a simple answer

Posted: Sun Aug 06, 2017 10:25 pm
by Xardas
Yes that fixed the Problem perfectly thanks. I have no idea why it didn´t work.

Topic Change :) Is there a simple way how i can make a Monster invulnerable?

Re: Ask a simple question, get a simple answer

Posted: Mon Aug 07, 2017 4:10 am
by Isaac
Xardas wrote:Is there a simple way how i can make a Monster invulnerable?
Plain Unkillable:

Code: Select all

myMonster.monster:setMonsterFlag("Invulnerable",true)
Shielded from all damage for a certain amount:

Code: Select all

myMonster:createComponent("GoromorgShield"):setEnergy(1000)

Re: Ask a simple question, get a simple answer

Posted: Wed Aug 09, 2017 4:19 pm
by akroma222
The options listed by Isaac are the way to go

Also worth mentioning are the monster component's onDamage & onDie hooks
Returning false in the onDamage hook will prevent the damage
Returning false in the onDie hook will prevent the monster dying
These can be useful in a number of situations

Re: Ask a simple question, get a simple answer

Posted: Wed Aug 09, 2017 9:15 pm
by Xardas
Thanks for that. I Chose to use Isaacs Option since it´s pretty simple to do. I needed it for some shopkeepers to be invulnerable.
Now that i have the Shops, i also wanted to make a Money changing machine which can choose between 3 states.
1. Change in Gold
2. Change in silver
3. Change in copper
I wrote the following Code for it and i can´t figure out why it won´t work. To mention is that i have made this Thing up out of codes i found here on the Forum. Mostly the stuff Isaac already gave me for some other Problems i had

Code: Select all

 function moneyinfo()
if kindcounter.counter:getValue() == 1 then
hudPrint("changing in gold coins")
end

if kindcounter.counter:getValue() == 2 then
hudPrint("changing in silver coins")
end

if kindcounter.counter:getValue() == 3 then
hudPrint("changing in copper coins")
end

if kindcounter.counter:getValue() >3 then
kindcounter.counter:setValue(0)
end
end

function surfaceContains(surface, item)
 for v,i in surface.surface:contents() do
 if i.go.name == item then return true
 end
end
end
----------------------------------------------------------
--counts coins
function moneychange()
local coinscopper ={}
local coinssilver ={}
local coinsgold ={}
   for v,i in moneychanger.surface:contents() do
 surfaceContains(moneychanger, "dm_coin_copper")
    if i then
      coinscopper[#coinscopper+1] = i 
    end
 surfaceContains(moneychanger, "dm_coin_silver")
    if i then
      coinssilver[#coinssilver+1] = i 
    end
  surfaceContains(moneychanger, "dm_coin_copper")
    if i then
      coinsgold[#coinsgold+1] = i 
    end
   end    
----------------------------------------------------------
if kindcounter.counter:getValue() == 1 then
local copper=#coinscopper%4
local silver=((#coinscopper/4)+#coinssilver)%4
local gold=((silver%4)+#goldcoins)
silver=silver/4
end
----------------------------------------------------------
if kindcounter.counter:getValue() == 2 then
local copper=#coinscopper%4
local silver=#coinscopper/4+#coinssilver+#coinsgold*4
local gold=0
end
----------------------------------------------------------
if kindcounter.counter:getValue() == 3 then
local gold=0
local silver=#coinssilver+#coinsgold*4
local copper=silver*4
silver=0
end
----------------------------------------------------------
for x = 0, #coinscopper do      
     coinscopper[x].go:destroy()
    end
for x = 0, #coinssilver do     
     coinssilver[x].go:destroy()
    end
for x = 0, #coinsgold do       
      coinsgold[x].go:destroy()
    end

for m=1,gold do
moneychanger.surface:addItem(spawn("dm_coin_gold").item)
end 
for m=1,silver do
moneychanger.surface:addItem(spawn("dm_coin_silver").item)
end
for m=1,copper do
moneychanger.surface:addItem(spawn("dm_coin_copper").item)
end
end
Once again it would be nice if you could tell me what´i did wrong here. :)
I hope the mistake(s) i made aren´t to great, so i can use this script afterall.

Re: Ask a simple question, get a simple answer

Posted: Thu Aug 10, 2017 10:06 am
by minmay
Isaac wrote:I wonder how it happened that a button's disableSelf setting doesn't disable the button?
It does disable the ButtonComponent. But ButtonComponent still triggers its onActivate hook (and therefore its connectors) even when disabled. The hook I posted makes it only trigger its connectors if enabled.

Re: Ask a simple question, get a simple answer

Posted: Thu Aug 10, 2017 6:52 pm
by Isaac
minmay wrote:
Isaac wrote:I wonder how it happened that a button's disableSelf setting doesn't disable the button?
It does disable the ButtonComponent. But ButtonComponent still triggers its onActivate hook (and therefore its connectors) even when disabled. The hook I posted makes it only trigger its connectors if enabled.
Well, changing the status of the button component doesn't seem to be the implied intent of a disableSelf option—or at least I hope not. Disabling the component should disable its actions, no?

Yes, I saw that in your script; it seems to be a good work around.