• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by t-pedrob · Mar 06, 2015 at 01:06 PM · databasedatasqldata storagequiz

[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?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fafase · Mar 06, 2015 at 01:41 PM 0
Share

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.

avatar image t-pedrob · Mar 06, 2015 at 02:36 PM 0
Share

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 :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image t-pedrob · Mar 06, 2015 at 02:42 PM 0
Share

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.

avatar image Cherno · Mar 06, 2015 at 03:09 PM 0
Share

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.

avatar image t-pedrob · Mar 06, 2015 at 05:27 PM 0
Share

Thanks for your time

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

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

Scriptable Objects as a datatable 1 Answer

How do I go about using a server to store and retrieve data? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges