I’m trying to create a cost for objects but for some reason when it initializes it runs the on_input function and passes the check as if the object is bought upon initialization.
Why does this fire as if I touch/click and release even though I haven’t done so? It actually hits buy_garden function even though I haven’t touched/released anything. Also the check_grid_boundary would return false.
function on_input(self, action_id, action)
if action_id == hash("touch") and action.released then
check_grid_boundary(self)
--check if enough money to buy garden if not reset position
if self.cost <= bank_balance.balance and self.initialized then
buy_garden(self)
else
reset_position(self)
end
elseif action_id == hash("right_mouse") then
check_grid_boundary(self)
end
end
You check for release only. Shouldn’t you check for both press and release in the same script? The press could happen in one script and the release in the one you are showing.
Clearly I’m doing something wrong. It’s basically saying I touched something (even when nothing is touched/clicked). It’s never saying I pressed a button though. But it goes to released and runs that part upon loading the main collection.
I do have a separate drag&drop script. Maybe this is interfering somehow. But I’m confused if I’m not touching/clicking anything why is this happening?
function on_input(self, action_id, action)
if action_id == hash("touch") then
print("I touched it")
if action.pressed then
print("Now I pressed it")
end
if action.released then
check_grid_boundary(self)
--check if enough money to buy garden if not reset position
print("poly ID: " , self.polyomino_id)
print("cost: ", self.cost)
print("balance: ", bank_balance.balance)
print("initialized: ", self.initialized)
print("off-grid: ", self.off_grid)
print("on-grid: ", self.on_grid)
print("------------------------------------")
if self.cost <= bank_balance.balance and self.initialized and self.off_grid == false then
buy_garden(self)
else
reset_position(self)
--self.initialized = true
end
end
elseif action_id == hash("right_mouse") then
check_grid_boundary(self)
end
end
Ok, I think I found it. I now go right to main collection from the bootloader and this doesnt’ happen. So the click on my start screen is bleeding over to my main collection somehow. Well at least I know where the issue is and can target a fix.