Hello, I am very new to Fuse, and I am loving what I have been able to do so far.
I am familiarizing myself with Fuse by creating a simple app that will essentially flip a coin. By this I mean, tap a circle and the text inside will say either “Heads” or “Tails”
After reading through a lot of examples and documentation, I thought I knew how it should be done, but the result I got was not what I expected.
Here is the relevant code:
<Page ux:Name="page1" Background="#04E762">
<Text Alignment="TopCenter" TextColor="#FFF" FontSize="64" Margin="20, 20, 20, 20" Value="Flip Coin"/>
<JavaScript>
function flipCoin(e) {
if (Math.random() < 0.5) {
return "Heads"
} else {
return "False"
}
}
module.exports = {
FlipCoin: flipCoin
};
</JavaScript>
<Text ux:Name="coin_value" TextColor="#04E762" Alignment="Center" FontSize="42" TextWrapping="Wrap" Value="Tap To Flip"/>
<Circle ux:Name="coin_circle" Fill="#FFFF" Width="80%">
<Tapped>
<Set Target="coin_value.Value" Value="{FlipCoin}"/>
</Tapped>
</Circle>
<WhileInactive>
<Set coin_value.Value="Tap To Flip"/>
</WhileInactive>
</Page>
The resulting behavior of the above code is for the text on top of the circle to change to “Fuse.Reactive.AsyncFunction” I assume I am missing something in how to integrate JavaScript code, but I can’t figure out what.
Any help would be much appreciated. Thank you.