Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - Mikael

#1
Help requests / (TGUI 1.0) Button single click
27 November 2022, 17:22:51
Hello, completely new here.

I couldn't find help in the official documents, tutorials nor examples about how to detect just a single mouse click/release on a button.

Button->OnClick() - Function executes multiple times when it's called?? Or is there another way to detect if the button was clicked? And it's not because of the for-loop. Even without it the functions get called multiple times.

 This is my code I'm trying to get to work:

void useItem(const Player::ptr& player, const Item::ptr& item)
{
if (!player)
return;

if (!item)
return;

item->use(player.get());
}

void HUD::update()
{
// Check if inventory slot was clicked
for (int i = 0; i < NUM_INVENTORY_SLOTS; ++i)
{
m_inventory[i]->onClick(useItem, m_player, m_player->getItemByIndex(i));
}

}