I have a qml item that presents a stimulus (image and sound) on the screen on a timer.
So I have a stimulus state as such:
State {
name: "stimulus"
extend: "running"
PropertyChanges {
target: getStimulus()
explicit: true
present: true
}
}
State {
name: "stimulus"
extend: "running"
PropertyChanges {
target: getStimulus()
explicit: true
present: true
}
}
To copy to clipboard, switch view to plain text mode
This state is entered when a timer fires. The getStimulus() function returns the stimulus item that I would like to present. It looks like this:
function getStimulus() {
console.log("GetStimulus() currIndex: "+currIndex+" value: "+sequence[currIndex])
var stimIndex = 0
if(sequence[currIndex] === 0) {// non-target
stimIndex = 1+Math.floor(Math.random()*(stimuli.children.length-1))
}
return stimuli.children[stimIndex]
}
function getStimulus() {
console.log("GetStimulus() currIndex: "+currIndex+" value: "+sequence[currIndex])
var stimIndex = 0
if(sequence[currIndex] === 0) {// non-target
stimIndex = 1+Math.floor(Math.random()*(stimuli.children.length-1))
}
return stimuli.children[stimIndex]
}
To copy to clipboard, switch view to plain text mode
As you can see, when the sequence of stimuli specifies a distractor stimulus, the function chooses a random one amongst the children of an Item that holds them.
This works perfectly with no warnings.
However now I want to prevent the same distractor stimulus being shown twice in a row. So I did this:
function getStimulus() {
console.log("GetStimulus() currIndex: "+currIndex+" value: "+sequence[currIndex])
var stimIndex = 0
if(sequence[currIndex] === 0) {// non-target
do { // FIXME this prints out spurious "Binding loop detected" warnings. Could rewrite by picking the index out of an array and removing the previous one.
stimIndex = 1+Math.floor(Math.random()*(stimuli.children.length-1))
} while (stimIndex === lastStimIndex);
lastStimIndex = stimIndex
}
return stimuli.children[stimIndex]
}
function getStimulus() {
console.log("GetStimulus() currIndex: "+currIndex+" value: "+sequence[currIndex])
var stimIndex = 0
if(sequence[currIndex] === 0) {// non-target
do { // FIXME this prints out spurious "Binding loop detected" warnings. Could rewrite by picking the index out of an array and removing the previous one.
stimIndex = 1+Math.floor(Math.random()*(stimuli.children.length-1))
} while (stimIndex === lastStimIndex);
lastStimIndex = stimIndex
}
return stimuli.children[stimIndex]
}
To copy to clipboard, switch view to plain text mode
This works exactly as I want it to, however on the console it prints out: QML PropertyChanges: Binding loop detected for property "target"
Not really a functionality problem, but this is very annoying. How do I avoid this warning? There is no actual binding loop here, there just happens to be a loop in the function to find the target.
Oddly enough, when I rewrote the function with an alternate method based on selecting the index out of an array, the binding loop warning is still there.
Bookmarks