- Home /
[Quiz game] How do I make players contribute with questions?
Hello guys, I'm doing a quiz game but I want to make players contribute to the game with questions. Any ideas of an easy and practical way of doing it?
Where and how to store and retrieve new questions?
Create a basic form with GUI where you have one field for the question, then let's say 4 field for the answer and a tick box defining the correct answer (you can use toggle for that or a simply integer field).
Have a send button that will parse the form into a json file that you send into a WWWForm.
Then your game will collect all the json forms that are found on the server and propose them.
Obviously, this sounds like a very vague answer but well, this question was not so precise and what, how and what you can do.
Hi, thanks for replying. You figured it out really quickly what my problem was. I'm new in this kind of stuff, so do you know any unity example able of parsing a form into a json file and send that into a wwwform and them SQL?
Thanks again :)
Answer by Cherno · Mar 06, 2015 at 01:37 PM
I would do it like this:
Crate a new class "Question":
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[System.Serializable]
public class Question {
public string questionText = "What currency does the United States use as of 2015?";
public List<string> answers = new List<string>() {"Dollar", "U.S. Dollar", "USD", "US Dollar"};
}
I use a list for the answer string so more than one answer can be correct if I wish.
Then, create a questionaire: Simply a list of the Question class:
public List<Question> questionaire = new List<Question>();
Now you can let players Add questions simply by adding to the list and filling in the values for questionText and answers.
To draw a random question:
string newQuestion = questionaire[Random.Range(0, questionaire.Count - 1)];
string questionTextCur = newQuestion.questionText;
To check if an answer is correct:
string answerText = "Euro";
if(newQuestion.answers.Contains(answerText)) {
Debug.Log("Right answer!");
}
else {
Debug.Log("Wrong answer!");
}
If by storing and retrieving you mean actually saving and loading to/from file, then look into Serialization and BinaryFormatters.
Hello, Thanks for you example it works well locally but my problem is not how to do it locally but how to get a new question created and send it to a server. Those new questions on the server will be retrived to other players game.
Any example of how to do this.
Thanks for your time.
Well, that kind of info would have been nice in the original question, wouldn't it? :) Unfortunately I have no experience with server-client communicatino.
Your answer
Follow this Question
Related Questions
Why PlayerPrefs not working although I use "HasKey" and Save() on android? 0 Answers
Linq Query - Strange Outcome 1 Answer
Storing data on a server to be used for player currency in a multiplayer game 1 Answer
How do I go about using a server to store and retrieve data? 0 Answers
How do I go about using a server to store and retrieve data? 0 Answers