I am trying to generate random numbers and then it works. Based on my code I also want to randomly select one out of the 5 random numbers as a correct answer. but when I do that and I want to see the value of the correct answer I dont see anything. Can someone tell me what I am doing wrong and how to go about it. Here is my Js code:
var Observable = require("FuseJS/Observable");
// var random1 = Observable();
var selector = Observable();
var random1 =Observable();
var random2 =Observable();
var random3 =Observable();
var random4 =Observable();
var random5 =Observable();
var correct_answer = Observable();
function gen() {
// body...
random1.value = Math.floor(Math.random()*(21-1) + 1);
random2.value = Math.floor(Math.random()*(31-11) + 11);
random3.value = Math.floor(Math.random()*(41-21) + 21);
random4.value = Math.floor(Math.random()*(51-31) + 31);
random5.value = Math.floor(Math.random()*(71-41) + 41);
selector.value = Math.floor(Math.random()*(5-0) + 0);
correct_answer.value = Observable(random1,random2,random3,random4,random5);
}
function generate() {
// body...
gen();
correct_answer.value = correct_answer.getAt(selector);
correct_answer.value = correct_answer;
}
// generate();
module.exports = {
random1: random1,
random2: random2,
random3: random3,
random4: random4,
random5: random5,
correct_answer: correct_answer,
generate: generate,
}
Preview detected an unhandled exception: Uno.AggregateException: One or more errors occurred. at Fuse.UpdateManager.Update(Fuse.Stage) at Fuse.UpdateManager.Update() at Fuse.AppBase.OnUpdate() at Outracks.Simulator.Application.OnUpdate() at Fuse.App.FrameCallback.doFrame(long) ERROR: Not handled: OnAdd Uno.Exception occured. at Fuse.Reactive.DataBinding1.Fuse.Reactive.IObserver.OnAdd(object) at Uno.Threading.IDispatcherExtensions.Arg1Invoke1.Run() at Fuse.Reactive.Dispatcher.Run() at Fuse.UpdateListener.Invoke() at Fuse.UpdateManager.Update(Fuse.Stage) at Fuse.UpdateManager.Update() at Fuse.AppBase.OnUpdate() at Outracks.Simulator.Application.OnUpdate() at Fuse.App.FrameCallback.doFrame(long)
An observable must either be a single value, or a list of values. If you databind it to a property, it must be a single value. Only if you use it for a list property such as <Each Items="{..}"> can it be an array.
A problem in your code is that correct_answer switches between being a list and a single value.
Yes, I just changed it when I realised and I saw that when I clicked my button I got the message on my UI saying “Fuse.Reactive.Observable” instead of a single number
var Observable = require("FuseJS/Observable");
// var random1 = Observable();
var selector = Observable();
var random1 =Observable();
var random2 =Observable();
var random3 =Observable();
var random4 =Observable();
var random5 =Observable();
var group_of_answer = Observable();
var correct_answer = Observable();
function generate() {
// body...
random1.value = Math.floor(Math.random()*(21-1) + 1);
random2.value = Math.floor(Math.random()*(31-11) + 11);
random3.value = Math.floor(Math.random()*(41-21) + 21);
random4.value = Math.floor(Math.random()*(51-31) + 31);
random5.value = Math.floor(Math.random()*(71-41) + 41);
selector.value = Math.floor(Math.random()*(5-0) + 0);
group_of_answer.add(random1,random2,random3,random4,random5);
group_of_answer.getAt(selector);
correct_answer.value = group_of_answer;
}
// generate();
module.exports = {
random1: random1,
random2: random2,
random3: random3,
random4: random4,
random5: random5,
correct_answer: group_of_answer,
generate: generate,
}
I get this error
LOG:
Preview detected an unhandled exception: Uno.AggregateException: One or more errors occurred.
at Fuse.UpdateManager.Update(Fuse.Stage)
at Fuse.UpdateManager.Update()
at Fuse.AppBase.OnUpdate()
at Outracks.Simulator.Application.OnUpdate()
at Fuse.App.FrameCallback.doFrame(long)
ERROR: Not handled: OnAdd Uno.Exception occured. at Fuse.Reactive.DataBinding1.Fuse.Reactive.IObserver.OnAdd(object) at Uno.Threading.IDispatcherExtensions.Arg1Invoke1.Run() at Fuse.Reactive.Dispatcher.Run() at Fuse.UpdateListener.Invoke() at Fuse.UpdateManager.Update(Fuse.Stage) at Fuse.UpdateManager.Update() at Fuse.AppBase.OnUpdate() at Outracks.Simulator.Application.OnUpdate() at Fuse.App.FrameCallback.doFrame(long)