I'd appreciate some help finishing this blockly maze.
https://blockly-games.appspot.com/maze?lang=en&level=10&skin=0
This how far I was able to get.
Not sure whether it is optimal solution, but it works:
while (notDone()) {
moveForward();
if (isPathLeft()) {
if (isPathForward()) {
if (isPathRight()) {
turnRight();
} else {
turnLeft();
}
} else {
turnLeft();
}
} else {
if (isPathRight()) {
turnRight();
}
}
}
Related
A little bit confuse about this simple use case :
I want to add a closure around an other one only with conditions.
For the moment, I only succeed to do this :
if(condition) {
my_root_closure {
my_main_closure {
do_stuff()
}
}
} else {
my_main_closure {
do_stuff()
}
}
I would like to do this without repeat the my_main_closure bloc.
To avoid repetition, you could create new closure that calls my_main_closure and store it in a variable:
def mmc = {
my_main_closure {
do_stuff()
}
}
if(condition) {
my_root_closure( mmc )
} else {
mmc()
}
What are some good examples of different ways to handle zero result search answer sets in result views?
Here's what I have right now. I assume I want to do size(this) < 1 but before I plunge ahead I want some ideas about what to do. For example, should I just say "search again" or should I try to recommend something to do?
render {
if (size(this) > 1) {
list-of (this) {
//default-sort-order {
// sorting(this.title)
// }
has-details (true)
where-each (item) {
layout-macro (content-thumbnail-card) {
param (content) {
expression (item)
}
}
}
}
} else-if (size(this) == 1) {
layout-match (this) {
mode (Details)
}
}
}
There is a NoResult dialog that will automatically activate for this condition:
https://bixbydevelopers.com/dev/docs/reference/ref-topics/dialog-modes.dialog-events#no-result-event
You can also place a conditional in your result view. For example:
result-view {
match: SomeConcept(this)
message {
if (size(this) == 0) {
template (No results)
}
}
render {
layout {
section {
content {
// No Result
if (size(this)== 0) {
paragraph(Sorry, I didn't find anything)
}
}
}
}
}
}
I'm really stuck and don't know what to do.
I've never worked in Bixby Studio and got that warning "page might be empty".
I've seen two similar posts about this problem, but they didn't help me at all.
item-selection-question {
first warning--> if (isFirstNavPage(page) && isLastNavPage(page)) {
template ("")
second warning--> } else-if (!isLastNavPage(page)) {
template-macro (HANDS_FREE_OPTION_ITEM_SELECTION_MORE_PAGES)
} else {
template-macro (HANDS_FREE_OPTION_ITEM_SELECTION_LAST_PAGES)
}
}
overflow-statement {
template-macro (HANDS_FREE_OPTION_OVERFLOW_STATEMENT)
}
overflow-question {
template-macro (HANDS_FREE_OPTION_OVERFLOW_QUESTION)
}
page-marker {
third warning--> if (!isFirstNavPage(page) && isLastNavPage(page)) {
template-macro (HANDS_FREE_OPTION_LAST_OPTION) {
param (page) {
expression (page)
}
}
}
}
I had a similar warning for,
content {
template ("Here's #{value(audioInfo.audioItem[audioInfo.startAudioItemIndex].artist)}.") {
speech ("Here's #{value(audioInfo.audioItem[audioInfo.startAudioItemIndex].title)}[ from #{value(audioInfo.audioItem[audioInfo.startAudioItemIndex].artist)}].")
}
}
WARN audioInfo.startAudioItemIndex might be empty
I changed the above snippet to,
content {
if(exists(audioInfo.startAudioItemIndex)){
template ("Here's #{value(audioInfo.audioItem[audioInfo.startAudioItemIndex].artist)}.") {
speech ("Here's #{value(audioInfo.audioItem[audioInfo.startAudioItemIndex].title)}[ from #{value(audioInfo.audioItem[audioInfo.startAudioItemIndex].artist)}].")
}
}
}
And it no longer shows the warning.
Try and see if it helps.
I am trying to create an input-view that will refresh every few seconds. The goal is to have a few buttons that increment and the user will click on the buttons when the buttons reach a 100. However, it seems like the action is waiting for an input so it is not updating. I found on the documentation that you can refresh an input-view, but I can't find any examples of it.
This is the code that I want to update:
input-view{
match: State(state){
to-input: UpdateGame
}
message{
template ("#{value(state.display)}"){
speech ("#{value(state.say)}")
}
}
refresh{
spec{
delay-seconds (2)
with-request{
intent{
goal: UpdateGame
}
}
}
}
render{
selection-of (state.options){
where-each (option){
cell-card{
slot2{
content{
primary{
template ("#{value(option)}")
}
}
}
}
}
}
}
}
There is one example of result-view in this doc
result-view {
match {
Activity (this)
}
refresh {
if (!exists(this.receipt)) {
spec {
delay-seconds (5)
with-request {
intent {
goal: CheckRideShareStatus
value {$expr(this)}
}
}
}
}
}
conversation-drivers {
if ("this.status == 'Requested' || this.status == 'Confirmed'") {
conversation-driver {
template ("Cancel my Uber ride")
}
}
}
render {
layout-match (this) {
mode (Details)
}
}
}
Sorry I've not caught this question earlier.
I've just verified that this issue is fixed in 20B SDK release.
Please refer the release notes for details about other changes.
I'm using aio_write it is working in a debug build but not in release. I've checked the constructor that everything is initialized and I'm not getting any warnings about uninitialized variables. The class collects data that is to be written to disc in 16K chunks. If the data is less than 16K, it works, even in release builds. If the data is larger than 16K, only the first chunk is written. WriteBuffer::ContinueWriteToFile returns WriteFileState_Active indefinitely.
WriteBuffer_posix.h:
class WriteBufferPlatformData
{
public:
WriteBufferPlatformData();
~WriteBufferPlatformData();
aiocb aioData;
WriteBuffer::BufferVector::iterator currentBuffer;
};
WriteBuffer_posix.cpp:
WriteBufferPlatformData::WriteBufferPlatformData() :
aioData(),
currentBuffer()
{
memset(&aioData,0,sizeof(aioData));
aioData.aio_fildes=-1;
}
WriteBufferPlatformData::~WriteBufferPlatformData()
{
if (0<=aioData.aio_fildes) {
close(aioData.aio_fildes);
}
}
WriteBuffer::WriteFileState WriteBuffer::StartWriteToFile(const char * filename)
{
NYMPH_ASSERT(0>m_platformData->aioData.aio_fildes);
m_platformData->aioData.aio_fildes=open(filename,O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
NYMPH_ASSERT2(0<=m_platformData->aioData.aio_fildes,"Could not open file for writing: %s (%d)",filename,errno);
if (0>m_platformData->aioData.aio_fildes) {
return WriteFileState_Failed;
}
if (m_buffers.empty()) {
close(m_platformData->aioData.aio_fildes);
m_platformData->aioData.aio_fildes=-1;
return WriteFileState_Complete;
}
m_isWriting=true;
m_platformData->currentBuffer=m_buffers.begin();
return ContinueWriteToFile();
}
WriteBuffer::WriteFileState WriteBuffer::ContinueWriteToFile()
{
NYMPH_ASSERT(0<=m_platformData->aioData.aio_fildes);
if (0!=m_platformData->aioData.aio_nbytes) {
int writeErrno=aio_error(&(m_platformData->aioData));
if (EINPROGRESS==writeErrno) {
return WriteFileState_Active;
}
NYMPH_ASSERT(aio_return(&(m_platformData->aioData))==m_platformData->aioData.aio_nbytes);
m_platformData->aioData.aio_nbytes=0;
++(m_platformData->currentBuffer);
if (m_buffers.end()==m_platformData->currentBuffer) {
close(m_platformData->aioData.aio_fildes);
m_platformData->aioData.aio_fildes=-1;
return WriteFileState_Complete;
}
}
if (0==m_platformData->aioData.aio_nbytes) {
m_platformData->aioData.aio_buf=*(m_platformData->currentBuffer);
if (m_buffers.back()==m_platformData->aioData.aio_buf) {
m_platformData->aioData.aio_nbytes=m_offset;
} else {
m_platformData->aioData.aio_nbytes=kBufferSize;
}
m_platformData->aioData.aio_offset=lseek(m_platformData->aioData.aio_fildes,0,SEEK_END);
if (0!=aio_write(&(m_platformData->aioData))) {
m_platformData->aioData.aio_nbytes=0;
NYMPH_ASSERT(EAGAIN==errno);
if (EAGAIN!=errno) {
close(m_platformData->aioData.aio_fildes);
m_platformData->aioData.aio_fildes=-1;
return WriteFileState_Failed;
}
}
}
return WriteFileState_Active;
}
Despite what I have read in the man page, it seems that calling aio_return is required and changing the NYMPH_ASSERT(aio_return... to NYMPH_VERIFY(aio_return... corrected the problem.