Is it possible to add value to some buttons?
Hello
I'm creating an experience using Fectar, and I'd like to know if adding value to buttons within my space is possible. Specifically, I'd like to create buttons that users can click to trigger specific actions or events within the experience. For example, a user can only open a chest if he has found all three keys. Is this possible to do within Fectar? And if so, what's the best way to add value to buttons?
Thanks!
-
Here's an example using code in a code block that should do what you want. This assumes you have spots called 'key1', 'key2' and 'key3' for each of the keys. The keys have to be clicked to be found.
var key1Found = false;
var key2Found = false;
var key3Found = false;
var key1 = Space.getSpot('key1');
var key2 = Space.getSpot('key2');
var key3 = Space.getSpot('key2');
var chest = Space.getSpot('chest');
function onClick(events)
{
if (events.spot.name == key1.name )
{
key1Found = true;
}
if (events.spot.name == key2.name )
{
key2Found = true;
}
if (events.spot.name == key3.name )
{
key3Found = true;
}
if (events.spot.name == chest.name)
{
if (key1Found && key2Found && key3Found)
{
// Write code here to execute if the chest is clicked while all keys are found.
}
else
{
// // Write code here to execute if the chest is clicked while not all keys are found.
}
}
}
0 -
Hi Matthijs,
Thanks for your reply and for sharing your code example! It's really helpful and well-structured.
Daniel
0
Please sign in to leave a comment.
Comments
2 comments