Professional Documents
Culture Documents
MY SUBREDDITS
POPULAR
-ALL
-RANDOM
ASKREDDIT
-PICS
-WORLDNEWS
-NEWS
-FUNNY
-TODAYILEARNED
-VIDEOS
-GAMING
-GIFS
-AWW
-MOVIES
-MILDLYINTERESTING
-IAMA
-SHOWERTHOUGHTS
-TELEVISION
-JOKES
-OLDSCHOOLCOOL
-NOTTHEONION
-LIFEPROTIPS
-SCIENCE
-MUSIC
-EXPLAINLIKEIMFIVE
-PERSONALFINANCE
-TWOXCHROMOSOMES
-SPORTS
-FOOD
-TIFU
-ASKSCIENCE
-SPACE
-GETMOTIVATED
-EARTHPORN
-ART
-PHOTOSHOPBATTLES
-WRITINGPROMPTS
-DOCUMENTARIES
-UPLIFTINGNEWS
-HISTORY
-GADGETS
-DATAISBEAUTIFUL
-FUTUROLOGY
-NOSLEEP
-BOOKS
-CREEPY
-PHILIPPINES
-DIY
-PHILOSOPHY
-LISTENTOTHIS
-INTERNETISBEAUTIFUL
-ANNOUNCEMENTS
-BLOG
MORE
gamemaker
COMMENTS
Community
Resources
Other
GameMaker is software designed to make developing games easy and fun. It features a unique "Drag-
and-Drop" system which allows non-programmers to make simple games. Additionally, experienced
coders can take advantage of its built in scripting language, "GML" to design and create fully-featured,
professional grade games.
subreddit_guidelines()
Content that does not follow the subreddit guidelines is subject to deletion, so please become familiar with
them.
1. Content must be directly related to GameMaker
2. Content must be in English
3. Content must not be obscene, illegal, racist or offensive
4. Content must not use "click-bait" titles, shortened links, or solicitation
5. Content must demonstrate a previous effort and research before posting and must provide
adequate detailed information
6. Show respect to all users of the subreddit and have patience with other users when providing
help
7. Promotional content must contribute to the community
8. Technical support requests are to be directed to YoYo Games Support
9. Content must be appropriately flaired at the time of submission
community()
Conversation
/r/gamemaker sponsors three chat-rooms: IRC, a Discord server, and a Slack team. Join in the
conversation, get help with any issues you might have and connect with your fellow developers!
Scheduled content
Schedule Content Summary
Saturday Screenshot Saturday Share the latest pictures and videos of your game
discussions in r/gamemaker
<>
1
Solved!Been making a fairly simple quiz game, but have hit a wall. Would love
some help! self.gamemaker
Submitted 2 years ago * by bassman2112
Hey all =)
Sadly I shan't be posting my project file because I'm using JCHTML5, and
don't feel right putting all of his work up for free; but I'll be copying in a lot
of the code I'm using.
So the simple premise: I'm making a game for little kids to help them with
music. They will hear a rhythm being played, and will answer "Yes" or "No"
as to whether it was the one they heard. I plan on doing a more interesting
version of this later where they hear the sound, and then pick one of three
rhythms; but simple for now.
So I have it working with one level - here is the code that makes it work:
First-off, when the room is created, it runs this script (this will later be a
script run by a level selector):
//Initialize variables
global.level_number = 1;
global.correct_answers = 0;
global.question_number = 1;
global.clickable = 1
//Create Questions
global.level1_questions =
ds_list_create();
ds_list_add(global.level1_quest
ions, obj_level1_1);
//And so on
ds_list_add(global.level1_quest
ions, obj_level1_12);
//Randomizes questions
ds_list_shuffle(global.level1_q
uestions);
//Referencing questions for
Level 1, providing answer in
"Yes" or "No" as string
//Answers currently all set to
"Yes" for debugging purposes
global.level_answers =
ds_map_create();
ds_map_add(global.level_answers
, obj_level1_1, "Yes");
//And so on
ds_map_add(global.level_answers
, obj_level1_12, "Yes");
instance_create(0, 0,
obj_current_question);
instance_create(0, 0,
obj_correct_answers);
if(global.level_answers[?
global.current_question.object_
index] == "Yes"){
//Disables
clicking/extra input
global.clickable = 0;
//audio_play_sound(snd_correct)
//Go to alarm
alarm[0] = 30;
}
else{
//Disables
clicking/extra input
global.clickable = 0;
global.question_number
+= 1;
//audio_play_sound(snd_incorrec
t)
//Go to alarm
alarm[0] = 30;
}
alarm[0]
ds_list_delete(global.current_l
evel_questions, 0);
This all works wonderfully. It keeps track of score, you can't slam on the
button 100 times and suddenly be at "question 100," et cetera.
The problem I'm having is that I want to have multiple levels; but I can't
figure out a way to properly move between them while keeping my button
code the same. I don't want to have to make an "obj_button_yes_level1"
that spawns when the user picks Level 1, for example. I just want to make
"obj_button_yes" so I'm not eating up valuable resource space.
I've tried this a few ways, neither of which has worked.
Firstly I made something that looked like this:
global.current_question_level =
string("global.level"+string(gl
obal.level_number)
+"_questions")
This one would spawn the initial question, as I wanted; but as soon as I
gave a single answer it would end - saying it had finished all of the
questions. I don't quite get why, tbh.
The second way I tried was this:
//Init
global.array_level_questions[25
] = 0
//Usage
global.current_level_questions
=
global.array_level_questions[gl
obal.level_number]
global.level1_questions =
ds_list_create();
ds_list_add(global.level1_quest
ions, obj_level1_1);
But this just straight-up doesn't work. It makes me think that, perhaps, GML
doesn't use arrays in the way I'm used to with other C-based languages?
Any guidance would be extremely appreciated =)
Sorry for the long post!!!
Edit:
Still broken.
So as talked about in the comments, I added a For loop to initialize the
variables; but that didn't help. I'll copy my starting script, as well as the
error it displays:
//Initialize variables
global.level_number = 1;
global.correct_answers = 0;
global.question_number = 1;
global.clickable = 1;
//Init
for (i = 0; i < 25; i++){
global.array_level_questions[i]
= 0;
}
global.level1_questions =
ds_list_create();
ds_list_add(global.level1_quest
ions, obj_level1_1);
//Et cetera
ds_list_add(global.level1_quest
ions, obj_level1_12);
//Randomizes questions
ds_list_shuffle(global.level1_q
uestions);
//Usage
global.current_level_questions
= 0;
global.current_level_questions
=
global.array_level_questions[gl
obal.level_number];
instance_create(0, 0,
obj_current_question);
instance_create(0, 0,
obj_correct_answers);
That line previously worked when I was not using the arrays, so I'm not sure
why it is not anymore D=
Again, any help would be massively appreciated
13 comments
share
report
all 13 comments
sorted by:
best
[]SaladLizard 1 point 2 years ago
Initialising that array like this:
global.array_level_questions[25]=0;
is only going to set the 25th value to 0, so the rest of the values are
undefined. Use a loop to define them all.
permalink
embed
[]bassman2112 S 0 points 2 years ago
[ ]
I assumed it would create and initialize everything up until that point haha -
guess GML doesn't work exactly like other C-based languages.
I'm on my phone, but would you do a for loop? Something like this?
For (i = 0; i > 25: i++) {
global.array_level_questions[i] = 0
}
Otherwise, does it seem like my syntax is reasonable?
Thanks a ton
permalink
embed
parent
[]TheWinslow 2 points 2 years ago
That for loop will never run but that is the basic idea.
permalink
embed
parent
[]bassman2112 S 1 point 2 years ago*
[ ]
Thanks =D
Sorry to bug, but would you be willing to take a look at my edit and see if
you have any advice? =)
permalink
embed
parent
[]TheWinslow 1 point 2 years ago
//Creating the
questions for
Level 1
global.level1_qu
estions = 0;
global.array_lev
el_questions[1]
=
global.level1_qu
estions;
global.level1_qu
estions =
ds_list_create()
;
ds_list_add(glob
al.level1_questi
ons,
obj_level1_1);
//Et cetera
ds_list_add(glob
al.level1_questi
ons,
obj_level1_12);
//Randomizes
questions
ds_list_shuffle(
global.level1_qu
estions);
//Init
for (i = 0; i
< 10; i++){
global.array_
level_questio
ns[i] = 0;
}
//Usage
global.curren
t_level_quest
ions = 0;
//-----------
-------------
-------------
-------------
-------------
----------//
//
LEVEL 1
QUESTIONS
//
//-----------
-------------
-------------
-------------
-------------
----------//
//Init
global.level1
_questions =
0;
//Creating
questions for
Level 1
global.level1
_questions =
ds_list_creat
e();
ds_list_add(g
lobal.level1_
questions,
obj_level1_1)
;
//Etc
ds_list_add(g
lobal.level1_
questions,
obj_level1_12
);
//Randomizes
questions
ds_list_shuff
le(global.lev
el1_questions
);
//Inserts
Level 1
questions
into proper
Array spot
global.array_
level_questio
ns[1] =
global.level1
_questions;
global.curren
t_level_quest
ions =
global.array_
level_questio
ns[global.lev
el_number];
permalink
embed
parent
[]mixmax2 1 point 2 years ago
i < 25
permalink
embed
parent
[]bassman2112 S 1 point 2 years ago
[ ]
//Usage
global.current_level_questions
=
global.array_level_questions[gl
obal.level_number]
Log in or Sign up
Forums>GameMaker>Programming>
1. This site uses cookies. By continuing to use this site, you are agreeing to
our use of cookies. Learn More.
Tags:
multiple choice
quiz
trivia
1.
pongsifuMember
Joined:
Jul 4, 2016
Posts:
2
It is simple enough to create a single multiple choice question, but the problem I'm having is
figuring out the most efficient way to make a multiple choice question pull from a pool of many
questions and corresponding answers.
So basically I'll have a question box and 4 answer boxes and I'll have a pool of questions and
those questions will each have 4 possible answers attached to them. Any help/suggestions in
the best way to do this would be appreciated as I'm having a hard time thinking of the best
solution for this. The methods I am thinking of I am sure are a lot more work than are actually
required and I know some of you will have a much more elegant solution.
pongsifu, Jul 4, 2016
#1
2.
jo-thijsMember
Joined:
Jun 20, 2016
Posts:
1,824
Hi and welcome to the GMC!
You can then keep selecting the first array in the list, save it to a temporary variable and read its
question and answers.
Then delete the first array from the list and you won't select the same question again.
3.
Ctl-FMember
Joined:
Jul 1, 2016
Posts:
59
I'd create a map to represent a question. And a list to hold the maps.
Code:
question = ds_map_create()
question[?"question"] = "what is the answer?"
question[?"ans1"] = "42"
question[?"ans2"] = "yes"
question[?"ans3"] = "idk"
question[?"ans4"] = "beats me"
question[?"correct"] = "ans1"
questions = ds_list_create()
ds_list_add(questions, question)
ds_list_mark_as_map(questions, ds_list_size(questions)-1)
Then when you want to display things and check the correct answer its easily layed out.
4.
pongsifuMember
Joined:
Jul 4, 2016
Posts:
2
Thank you for the help, this is pretty much exactly what I needed. It has been a long long time
since I have used GM so I'm basically re-learning from scratch (because I forgot everything). I
watched some videos on ds_lists and ds_maps and I understand how to create the list itself and
its purpose, but I'm still not sure how to actually pull from the list.
What I mean is, say I have a room with 4 blank answer boxes and 1 blank question box, I don't
know how to actually get the list to populate the question/corresponding answers into their
boxes. I set the boxes as their own objects but it may be better to simply use coordinates to line
up on top of the boxes. Either way, I'm feeling kind of silly for not being able to figure out
something that should be simple (I chose this as a project because I wanted to try something
easy to help re-learn everything). Previously I had relied on the pre-made "action" things GM is
known for rather than using code and I told myself I'd try to use code more instead...but maybe
that isn't the best idea, as I really am terrible at coding.
pongsifu, Jul 5, 2016
#4
5.
jo-thijsMember
Joined:
Jun 20, 2016
Posts:
1,824
Nah, coding is fun!
There are many applications by now that will convert D&D actions to code,
so if you know how to do something in D&D and want to know how it could look like in code,
you can use one of those tools to learn the syntax.
Examples are:
https://forum.yoyogames.com/index.php?threads/drag-and-drop-to-gml-converter.138/
and:
http://www.softpedia.com/get/System/File-Management/D-and-D-to-GML-Converter.shtml
Anyway, as to get the information from the array to the other objects,
you could have 1 object pick an array from the list and store it in a global variable.
The other objects can then read the information from the global variable.
So, you would have a controller object (mayby the box with the question in it)
with this in its create event:
Code:
global.qInfo = ds_list_find_value(global.mcQuestion, 0);
ds_list_delete(global.mcQuestions, 0);
And you could then use the instance creation code (room editor, right click on instance,
"creation code") to assign every button object its status:
Code:
// Button with first answer
myAnswer = global.qInfo[1];
amICorrect = global.qInfo[5] == 1;
You would replace 1 with 2 here for the button with the second answer and so on.
jo-thijs, Jul 5, 2016
#5
Charliebailey03 likes this.
6.
Charliebailey03Member
Joined:
Mar 28, 2017
Posts:
70
can anyone tell me what a map is?
Charliebailey03, May 7, 2017
#6
7.
jo-thijsMember
Joined:
Jun 20, 2016
Posts:
1,824
Charliebailey03 said:
can anyone tell me what a map is?
In GameMaker, maps look like lists, but have as big difference that lists only accept numbers as
indices/keys and need a value at every index they have.
Maps however accept strings as indices/keys too.
You can then keep selecting the first array in the list, save it to a temporary variable and read its question and
answers.
Then delete the first array from the list and you won't select the same question again.