News:

HOT TIP! Exploring the commands packaged in VC's standard configurations is a great way to learn how to build your own. You can also clone a command as a starting point: just right-click and select "Clone" (or type Alt-C).

Main Menu

How to handle when no map entries found?

Started by jb5349, September 27, 2014, 11:45:36 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jb5349

So I have a map setup with favorites and with relationships. I can have VC store a new entry such as  color and blue with color being key and blue being the value.

However, my issue is not with creating new keys/values or looking up existing ones, but with how to handle when no key/value exists yet.

For example, I ask, what is my favorite food. VC checks for the key food and it doesn't exist yet, so I want it to return, "I don't know, perhaps you can teach me that"

I tried using {EMPTY} but that did not work.

Any ideas? Thanks!

jitterjames

Yes you can do the following:

- Use the Map.Get action
- Followed by a logic block that checks LastActionSuccess.

put "I don't know, perhaps you can teach me that"  in the else actions

jb5349

Awesome thanks! I just couldn't figure out how to go about it! That helps a lot!

jb5349

Just to add to that, you also need VC.StopMacro after that so it doesn't go ahead and try to give the normal response and ends the Macro.

So I have it working like this..

If var.CUser = Jeff then

Map.Get JeffsFavs {1}

This checks to see who is talking, and gets the correct list of favorites (Map). {1} is the result of the list of options I provided in the command. (i.e. color, song, food, etc.)

If Last Action Success

Else

TTS.Speak "I don't know"

VC.Stop Macro

Then below that I have the normal response if all else works. I could probably put this in LastActionSuccess as well and not use the stop macro. So it works either way, but at least with the way I have it I can disable the checking for nothing if I had to.

TTS.Speak "Your favorite {1} is {LastResult}

jitterjames

Quote from: jb5349 on September 27, 2014, 12:45:15 PM
Just to add to that, you also need VC.StopMacro after that so it doesn't go ahead and try to give the normal response and ends the Macro.

Yes, but you only need to do this if you have other actions after the logic block.  If you put all your other actions into the "then" portion of the logic block, then you don't need to use stopMacro.  It depends on how you write your command macro.