Author Topic: How to handle when no map entries found?  (Read 1698 times)

0 Members and 1 Guest are viewing this topic.

jb5349

  • Jr. Member
  • **
  • Posts: 46
  • Karma: 2
    • View Profile
How to handle when no map entries found?
« on: September 27, 2014, 11:45:36 AM »
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

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: How to handle when no map entries found?
« Reply #1 on: September 27, 2014, 11:58:33 AM »
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

  • Jr. Member
  • **
  • Posts: 46
  • Karma: 2
    • View Profile
Re: How to handle when no map entries found?
« Reply #2 on: September 27, 2014, 12:23:27 PM »
Awesome thanks! I just couldn't figure out how to go about it! That helps a lot!

jb5349

  • Jr. Member
  • **
  • Posts: 46
  • Karma: 2
    • View Profile
Re: How to handle when no map entries found?
« Reply #3 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.

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

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: How to handle when no map entries found?
« Reply #4 on: September 27, 2014, 01:26:58 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.