I am trying to build a quiz game using alexa.net. However i´ve run into a potential problem.
Whenever the user has answered a question and the answer has been evaluated i want to immediately ask another question.
As it is right now, the user has to manually request another question. What i would like to have happen, was that the intent that handles the question keeps calling itself until the user actively chooses to end the game.
Is that even possible? If so, can anyone point me in the right direction, maybe even write up a brief hello-world style example?
Suppose you want to create a math quiz game where Alexa will ask you random math questions and you have to provide the right answer. The game has to continue until the user ask specifically to quit.
Create an AnswerIntent which is triggered when the user says an answer. Our answers are numbers, so create this intent with AMAZON.NUMBER slot which lets you capture the numbers spoken. (Choose your slot according to the answers for your questions).
Sample utterance for AnswerIntent:
{number}
the answer is {number}
is it {number}
{number} -> AMAZON.NUMBER slot
So each time when the user says an answer to your question you will receive a POST request in your backend with the intent triggered (in this case AnswerIntent), slot and its value. Then:
Validate the answer.
Update the score (if at all your usecase has a score)
Generate the next question.
Provide a response with the next question.
You will only receive a request at your backend when there is a user interaction. So make sure that when the user says an answer, your response has the next question to asked. In this way the user can continue answering questions without asking for a question explicitly.
Sample Interaction:
User : Alexa, open math quiz
Alexa: Welcome to math quiz. Here is your first question.
What is the sum of five and four.
[you will receive the launch request and your response has the first question]
User : Nine
[you will receive AnswerIntent request, with number slot having value 9.
Validate the answer and generate the next question]
Alexa: Correct!. Here is your next question.
What is the product of ten and five.
User : Twenty.
Alexa: Wrong, the right answer is fifty.
here is your next question.
What is sum of two and six.
User : Stop
[AMAZON.StopIntent is triggered and you can now end the game.]
Alexa: Bye.
Use sessionAttributes to store some information about the question or its answer so that you can validate it easily at the backend when your receive a response from the user.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
First of all, im sorry if this question was already responded by someone, but im new to Stackoverflow and im trying to make my first program in C# with visual studio.
Im making a bank program with object oriented programmation, i already done a few methods so the user can deposit and withdraw money, but i dont know how to apply this methods to the Console. Here is my code, and what im trying to do is pause the program till the user sets the information needed, the money and the string of the note (like 80$ "dinner with Joe").
case "/deposit":
//Make the deposit
account.MakeDeposit(Console.Read(), DateTime.Now,Console.ReadLine());
break;
The requierements of the method are a decimal for the amount, the date time that is not a problem, and the string.
It only takes the first character of the command line, for example if i want to deposit 8000$ it will only take the 8. Then the option for the string doesnt even pop up. I wanted to make like a console feedback too, so when i run the command /deposit it prints like: "How much money?" and that stuff.
I need help to break down the method in parts so i can inject the decimal ammount and the string.
Any advices, tips and tutorials are welcome.
Ty guys!
Break down the parts of your application reading input from the console from the parts of the app that process the data. You can then concentrate on one thing at a time. As such, the call to Console.Read does not belong as an argument to account.MakeDeposit. It makes it hard to debug and you will get a mess at the end.
To wait for user input use string input = Console.ReadLine();
Then to convert the string into an amount use
if( decimal.TryParse(input, out decimal amount))
{
// success! do something with 'amount'
}
else
{
Console.WriteLine("Invalid Input. Expected decimal value");
}
Okay so what i made, as Tarik told me is break down the code, with a method will be better but i created empty variables to store the information code gaved by the user, its a bad way to resolve it but im really new to this so it works for me, here is the code:
case "/deposit":
//Deposit Money
decimal C;
string D;
Console.WriteLine("How much you want to deposit?");
C = Convert.ToDecimal(Console.ReadLine());
Console.WriteLine("Add a note:");
D = Console.ReadLine();
account.MakeDeposit(C, DateTime.Now, D);
Console.WriteLine($"Maked a deposit of {C.ToString()}$!");
break;
Ty guys for the help!
Any way to improve it will be appreciated guys.
I want to track a simple Firebase event in my mobile game - When the player hits a score of 25, I want them to be labeled as an "active_player"
The code I got from my programmer looks like this, but it doesn't track in Firebase. Any thoughts of what could be wrong?
public void ReportScore(int score)
{
Social.ReportScore(score, GPGSIds.leaderboard_total_icons,(bool success) =>
{
Debug.Log("Score reported: " + score);
if (score == 25)
{
Firebase.Analytics.FirebaseAnalytics.LogEvent(
Firebase.Analytics.FirebaseAnalytics.EventSelectContent,
new Firebase.Analytics.Parameter("active_player", score));
}
}
}
If I understand the question correctly, you want to create an audience of players whose scores are above 25. What the code there does is log an EventSelectContent event with a parameter "active_player" whose value is 25.
To create an Audience of people who have logged that event with that parameter.
I don't think this is the best way to achieve your goal though. You can create your own events. For example, you could replace the above line with:
Firebase.Analytics.FirebaseAnalytics.LogEvent("active_player");
at which point you could create an audience of everyone whose logged that event without diving into parameters.
But what I think you really should do is set a user property. This way you can easily categorize all the users who've achieved this goal. You could say something like:
FirebaseAnalytics.SetUserProperty("gamertype", "active");
to mark a user as active.
Finally, I'm not sure what your overall goals are, but you may actually be better served by Firebase Predictions. A prediction that's automatically calculated for you is "churn" or "a user about to stop playing your game" or "not churn" which is basically your active player. Predictions do need more daily active users before they're active, but they have the potential of being the most beneficial if you're trying to take pre-emptive measures to retain your users. I think this Medium post can shed more light on why you might choose predictions over just an analytics property.
Hopefully this helps!
--Patrick
I have a question I am stumped on.
Okay, this is for a game of mine in Unity3D.
To make this make sense in terms of what people normally play.
Let's say the player has 500 Gold in their account (saved on database).
And the player earns 243 gold by doing some kind of task, how could the game
(Unity3D) tell the PHP file they earned specifically 243 Gold?
Because here's where the issue lies,
In Unity3D there's a class called WWW.
It allows you to send some sort of string to a PHP file.
int currentGold;
string goldToSend = currentGold.ToString(); // Only using that for example.
WWWForm form = new WWWForm();
form.AddField("NameOfPostRequestInPHPFile",goldToSend);
WWW www = new WWW("website.com/PHPFile.php", form);
Now as you can see, I am in a pretty big dilemma, being you can't trust the client with anything, how would one actually send a random gold amount from the client side to the PHP to then put into a database.
The issue I am facing is, how can one really make a PHP understand what's going on in the game without the client actually telling it a thing, and being you can't trust the client, how can the client actually tell the PHP to load, use this data and then put it into the database.
I thought about using hashes an stuff, but then that still brings up the problem client side.
Lets say
if(sentGold == 243){
string hash = hash01;
// Change it to hash1000 (to get 1000 gold).
}
if(sentGold == 1000){
string hash = hash1000;
}
As you can see, using if statements clearly wouldn't work either, because then the hashes could just be changed locally to fit their devious attempts. Plus it looks like garbage to had 20K if statements.
I know it's impossible to entirely stop hacking. But at the same time, if I do something i want to do it right, not half-a**ed if you get what I mean?
If you've made it to this point reading my help message.
I really appreciate the time you've put into reading it,
it means a lot to me.
Now, if there's some other technology or hints you might know that could help me with this, or heck even a tutorial on it (i've been looking for days), but I'm still deadlocked because nobody is addressing the fact that yeah they might use secret keys and so forth, but they are failing to address that the string they send can be easily tampered with. All they gotta do is change for 243 to 9999999999 and then they are rich.
You can't trust the client? Correct.
But...You are the captain of this ship. So your server need to be smart enough to detect the cheating.If a certain task in game gives 200 gold, you can send the reference of that task along with the value (200,"SomeTask"). Now if client tries to send (10000,"SomeTask"), server would consider it cheating. You might say that client can earn variable gold based on how good they perform the task, in that case you can have a max-limit value for every task and check before adding the gold to database.
And never send total gold from client to be saved in database. Client should only be able to send newly earned gold and will gets back total value.
For Example:
Database: 2000 gold -> Game: 2000 gold
Game: POST (130,"pickupjewel");
Databse: if (130 <= MaxValue("pickupjewel")) [TRUE] -> SUCCESS
Database: 2130 gold -> Game: 2130 gold
Game: POST (999999,"pickupjewel");
Databse: if (999999<= MaxValue("pickupjewel")) [FALSE] -> FAILURE
Database: 2130 gold -> Game: 2130 gold
I hope this helps. Let me know if you have any specific issue.
I'm not to familiar with the SO user tags, so I hope that this works: #aaron
This is the closest question that I could find that relates to my issue, but it's not exactly the issue. (I tried Google, Bing, and SO's own search.)
https://stackoverflow.com/questions/25014006/nullreferenceexception-with-parseobjects-in-array-of-pointers
My issue: I have a Unity Web-Player game that interfaces with both Facebook and Parse. after resolving many issues in it, I have it to where it will easily connect to Facebook, pull in the user's profile information and picture. It then attempts to connect to parse to log the user into parse to retrieve their game related data (like high scores, currency stats, power ups, etc.) and when it tries to do that, I get a NullReferenceException. The specific contents of the error message is:
"NullReferenceException: Object reference not set to an instance of an object
at GameStateController.ParseFBConnect (System.String userId, System.String accessToken, DateTime tokenExpiration) [0x0001a] in C:...\Assets\Scripts\CSharp\CharacterScripts\GameStateController.cs:1581
at GameStateController.Update () [0x0011f] in C:\Users\Michieal\Desktop\Dragon Rush Game\Assets\Scripts\CSharp\CharacterScripts\GameStateController.cs:382"
The code that generates this error message is:
public void ParseFBConnect(string userId, string accessToken, DateTime tokenExpiration)
{
Task<ParseUser> logInTask = ParseFacebookUtils.LogInAsync (userId, accessToken, tokenExpiration).ContinueWith<ParseUser> (t =>
{
if (t.IsFaulted || t.IsCanceled)
{
if (t.IsCanceled)
Util.LogError ("LoginTask::ParseUser:: Cancelled. >.<");
// The login failed. Check the error to see why.
Util.LogError ("Error Result: " + t.Result.ToString ());
Util.LogError ("Error Result (msg): " + t.Exception.Message);
Util.LogError ("Error Result (inmsg): " + t.Exception.InnerException.Message);
}
if (t.IsCompleted)
{ // No need to link the user to a FB account, as there are no "real" (non fb) accounts yet.
Util.Log ("PFBC::Login result reports successful. You Go Gurl!");
// Login was successful.
user = t.Result; // assign the resultant user to our "user"...
RetryPFBC = false;
return user;
}
return t.Result;
});
if (user.ContainsKey ("NotNew"))
{ // on true, then we don't have to set up the keys...
Util.Log ("User, " + user.Username + ", contains NotNew Key.");
}
else
{
CreateKeys (); // Create Keys will only build MISSING Keys, setting them to the default data specifications.
user.Email = Email;
user.SaveAsync (); // if we have created the keys data, save it out.
}
}
It is being passed the proper (post authenticated) Facebook values (FB.UserId, FB.AccessToken, FB.AccessTokenExpiresAt) in that order. I'm using FB Sdk version 6.0.0 and Parse Unity SDK version 1.2.16.
In the log file, instead of any of the debug.log/Util.log comments, it does the "Null Reference" error (above), followed by "About to parse url: https://api.parse.com/1/classes/_User
Checking if https://api.parse.com/1/classes/_User is a valid domain
Checking request-host: api.parse.com against valid domain: *"
And that is where it just stopped. So, I built a simple retry block in the Update() function to call the ParseFBConnect() function every 10 or so seconds. Which, seems to only fill up my log file with the same error sets. After searching across the internet for help, I tried changing the FB.AccessTokenExpiresAt to DateTime.UtcNow.AddDays(1) as others have said that this works for them. I cannot seem to get either to work for me. When I check the Dashboard in Parse to see if it shows any updates or activity, it doesn't, and hasn't for a few days now. The Script Execution Order is as follows:
Parse.ParseInitialzeBehaviour -- -2875 (very first thing)
Facebook loaders (FB, Editor, Canvas, etc) -- -1000 to -900
GameStateController -- -875
...
So, I know that the Parse.ParseInitializeBehaviour is being loaded first (another result of searching), and I have tracked the NullReference down to the Parse.Unity.dll by changing where the login method is stored; The GSC is on the player (the Player starts in the splash screen and remains throughout the entire game). I have also tried placing the Parse.ParseInitializeBehaviour on the Player gameobject and on an empty gameobject (with a simple dontdestroy(gameObject) script on that). And, I have my Application ID and my DotNet Key correctly filled in on the object.
When I first set up parse, and on the current production version of the game, it can successfully create a user account based off of the code snippet above. Now, it just breaks at the trying to parse the url...
So, My Question is: What am I doing wrong? Does anyone else have this issue? and does anyone have any ideas/suggestions/etc., on what to do to fix this? I really just want this to work, and to log the user in, so that I can grab their data and go on to breaking other things in my game :D
All help is appreciated!! and I thank you for taking the time to read this.
The Answer to this question is as follows:
backend as a service - Bing
Ditch parse because it doesn't work well with Unity3d, the support (obviously, judging by the sheer number answers to this question and other questions from people that need help getting it to work) is extremely lacking, and most, if not all, of the examples to show how to use it are broken / missing parts / etc. I see this as a failure on the part of the creators. I also see it as False Advertising. So, to answer this question - PARSE is a waste of time, cut to the chase and grab something that does work, has real, WORKING examples, and that is maintained by someone that knows HOW TO PROGRAM in the UNITY3d environment.
A great example of this would be the Photon Networking service, App42 by Shephertz.com, Azure by Microsoft, etc. With the overwhelming number of answers to this, if you exclude PARSE, This should have been a no-brainer. I've included a Bing Search link, you can also do a quick search for Gaming Backends (you'll find blogs and reviews.)
I suggest strongly, that you read the reviews on these services, read the questions (and make note of whether they have been answered, or, in the case of Parse, if they simply closed the forum rather than answering their customers)... And, just bounce around through the examples that they give for using their products. If they show how it works, and expected results (like the MSDN does) you'll have a lot better and a lot easier time getting it work.
FYI - My game now has all of the back end integrations, saves/creates/gets users & their data, has a store, and is moving right along, since I dropped PARSE.
To make things correct, I WAS using Parse 1.2.16 for unity, and the Facebook for Unity SDK 6.0.0... I tried Parse 1.2.14, with the same results, and I tried both Unity 4.5.2 and 4.5.3. My opinion of Parse is based off of their documentation, these 2 API versions, and the very long days that I pulled trying to get it to work. I then added in the fact that NO ONE here answered this question AT ALL (Sadly, Stack Over flow is Facebook's preferred Help/Support forum. They even say in their blogs, help documentation, etc., that if you have an issue - post your question on Stack Overflow.com with relevant tags. Which, I did.)
Oh, and the final star rating of Parse (to clarify it) is "-2 out of 5" -- That's a NEGATIVE 2 stars... out of 5. as in, run away from it... far, far away. Just to clarify.
I recently launched my humble side project and would like to add a "related submissions" section when viewing a submission. Exactly like what SO is doing here - see right column, titled "Related"
Considering that each submission has a title and a set of tags, what is most effective (optimum result), most efficient (fast, memory friendly) way to query the database for related submissions?
I can think of one way to do this (which I'll post as an answer) but I'm very interested to see what others have to say. Or perhaps there's already a standard way of achieving this?
Here's my two cent solution:
To achieve the best output, we need to put “weight” on the query results.
To start with, each submission in the database is assumed to have a weight of zero.
Then, if a submission in the "pool" shares one tag with the current submission, we'd add +3 to the found submission. Hence, if another submission is found that shares two tags with the current submission, we add +6 to the weight.
Next, we split/tokenize the title of the current submission and remove “stop words”.
I’ve seen a list of stop words from google, but for now I’ll define my stop words to be: [“of”, “a”, “the”, “in”]
Example:
Title “The Best Submission of All Times”
Result the array: ["The", “Best”, “Submission”, “of”, “All”, “Times”]
Remove stop words: [“Best”, “Submission”, “All”, “Times”]
Then we query the database for submissions containing any of the mentioned titles, and for each result we add the weight: +2
And finally sort the list descending by weight and take the top N results.
What do you think? (be gentle!)
If I understand well, you need a technique to find whether two posts are "similar" one to each other. You may want to use a probabilistic model for that:
http://en.wikipedia.org/wiki/Mutual_information
The idea would be to say that if two posts share a lot of "uncommon" words, they are probably speaking on the same topic. For detecting uncommon words, depending on your application, you may use a general table of frequencies, or maybe better, build it yourself on the universe of the words of your posts (but you will need to have enough of them to have something relevant).
I would not limit myself on title and tags, but I would overweight them in the research.
This kind of ideas is very common in spam filtering. I unfortunately the time to make a full review, but a quick google search gives:
http://www.aclweb.org/anthology/P/P04/P04-3024.pdf
karlmicha.googlepages.com/acl2004_poster.pdf