• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

Beginner help needed rock,paper,scissors

MoriMori

Member
GML:
sprite_index = choose(
spr_card_paper,spr_card_rock,
spr_card_scissors);
This was made in the create event with
obj_cards, which is a parent to the objects;
obj_paper, obj_rock, obj_scissors

Now if you've played rock, paper, scissors then you understand how the game works, now I need help on what to code next as I want to code in

rock beats scissors but paper beats rock
paper beats rock but scissors beat paper

one player is you and the other is the computer and i'm not sure how to make the computer work where it chooses rock, paper, scissors from random

If it draws the round restarts and it's a best out of three and how would I declare victory and loss in rounds

I know it's so much to ask for but I would love to have guidance as a beginner ☺
 

Squeegee209

Member
Well, here's what I would do.

For the pick randomly, just add another variable for the computer's choice, such as "var_cpuchoice"
Then, add

randomize();
//makes sure that everything generates a new random seed
var_cpuchoice = irandom_range(0, 2);
//makes the computer generate a random number, or paper, rock, or scissors, and then assign it to said variable

Then, for the who wins, just put this, I guess (there's probably a faster way to do it, but I don't know it)

var_userchoice = obj_card.image_index;
//gets the image_index of the card object and assigns it to var_userchoice
if var_userchoice = 0 && var_cpuchoice = 1 {
var_result = "Win";
}
if var_userchoice = 0 && var_cpuchoice = 2 {
var_result = "Lose";
}
if var_userchoice = 1 && var_cpuchoice = 0 {
var_result = "Lose";
}
if var_userchoice = 1 && var_cpuchoice = 2 {
var_result = "Win";
}
if var_userchoice = 2 && var_cpuchoice = 0 {
var_result = "Win";
}
if var_userchoice = 2 && var_cpuchoice = 1 {
var_result = "Lose";
}
if var_userchoice = var_cpuchoice {
var_result = "Draw"
}

If you need any other help, I can reply again. I hope this works for you!
 
Last edited:

MoriMori

Member
Well, here's what I would do.

For the pick randomly, just add another variable for the computer's choice, such as "var_cpuchoice"
Then, add

randomize();
//makes sure that everything generates a new random seed
var_cpuchoice = irandom_range(0, 2);
//makes the computer generate a random number, or rock, paper, or scissors, and then assign it to said variable
I add this within the same create event correct? :)
 

MoriMori

Member
Well, here's what I would do.

For the pick randomly, just add another variable for the computer's choice, such as "var_cpuchoice"
Then, add

randomize();
//makes sure that everything generates a new random seed
var_cpuchoice = irandom_range(0, 2);
//makes the computer generate a random number, or rock, paper, or scissors, and then assign it to said variable
So I added in the computers choice in the create event, do I need to code out turns as to who goes first player or computer or should I do the main element
Paper beats rock ect...
 

Squeegee209

Member
Yes, in the Create event.

As for the turn, just have the card object figure out what happens in the Step event once your choice is picked.
I don't think you really need a turn though, just have them both go at the same time?
If I'm being honest, I don't know much about the "choose()" thing, so I'm not entirely sure if what I said will work.
 

MoriMori

Member
Yes, in the Create event.

As for the turn, just have the card object figure out what happens in the Step event once your choice is picked.
I don't think you really need a turn though, just have them both go at the same time?
If I'm being honest, I don't know much about the "choose()" thing, so I'm not entirely sure if what I said will work.
Okay! I see
I'm using a test game first before coding it into the legit one so it's fine to make mistakes if there is! ^^

But the next issue I have would be for the step event what would I input
Would it be an if statement? If so what expression/ statement would I use?

GML:
if (insert part) then
{
<statement>;
<statement>;
}
Would this work? I'm not sure how to do it at all honestly 😅
 

MoriMori

Member
Okay! I see
I'm using a test game first before coding it into the legit one so it's fine to make mistakes if there is! ^^

But the next issue I have would be for the step event what would I input
Would it be an if statement? If so what expression/ statement would I use?

GML:
if (insert part) then
{
<statement>;
<statement>;
}
Would this work? I'm not sure how to do it at all honestly 😅
OH WAIT ALL YOUR CODE HADN'T SHOWN UP
 

MoriMori

Member
Yes, in the Create event.

As for the turn, just have the card object figure out what happens in the Step event once your choice is picked.
I don't think you really need a turn though, just have them both go at the same time?
If I'm being honest, I don't know much about the "choose()" thing, so I'm not entirely sure if what I said will work.
Okay now I realized for the if statement you've put does this still all go in the create event or step event?
 

TailBit

Member
Here is a short version of the result comparing:
GML:
if (var_cpuchoice == var_userchoice) var_result = "Draw";
else var_result = (var_cpuchoice == (var_userchoice +1) mod 3)?"Lose":"Win";
hopefully my use of: argument?a:b is correct
 

MoriMori

Member
Yes, in the Create event.

As for the turn, just have the card object figure out what happens in the Step event once your choice is picked.
I don't think you really need a turn though, just have them both go at the same time?
If I'm being honest, I don't know much about the "choose()" thing, so I'm not entirely sure if what I said will work.
Okay okay so I typed out all of the code but there is one major issue the red all says expected expression and the yellow syas the variable has only been refrenced one
 

Attachments

MoriMori

Member
Here is a short version of the result comparing:
GML:
if (var_cpuchoice == var_userchoice) var_result = "Draw";
else var_result = (var_cpuchoice == (var_userchoice +1) mod 3)?"Lose":"Win";
hopefully my use of: argument?a:b is correct
Where would this need to go into ?^^,
 

MoriMori

Member
Here is a short version of the result comparing:
GML:
if (var_cpuchoice == var_userchoice) var_result = "Draw";
else var_result = (var_cpuchoice == (var_userchoice +1) mod 3)?"Lose":"Win";
hopefully my use of: argument?a:b is correct
I attempted to input the code but it comes up with expected expression do you know how to fix this?:)
 

MoriMori

Member
Here is a short version of the result comparing:
GML:
if (var_cpuchoice == var_userchoice) var_result = "Draw";
else var_result = (var_cpuchoice == (var_userchoice +1) mod 3)?"Lose":"Win";
hopefully my use of: argument?a:b is correct
Okay I figured out the issue may be the fact that there isn't a variable assigned to result so what would I put for the result variable if that is the problem?
 

MoriMori

Member
Yes, in the Create event.

As for the turn, just have the card object figure out what happens in the Step event once your choice is picked.
I don't think you really need a turn though, just have them both go at the same time?
If I'm being honest, I don't know much about the "choose()" thing, so I'm not entirely sure if what I said will work.
Okay I figured out the issue may be the fact that there isn't a variable assigned to result so what would I put for the result variable if that is the problem?
 

Squeegee209

Member
btw, i just noticed something
in your image, some of the variables are written as
var _(something)
instead of
var_(something)

i recommend keeping them consistent, so as not to get an error.

as well, im typing this without being on gamemaker currently, so sorry if i made a mistake
 

MoriMori

Member
btw, i just noticed something
in your image, some of the variables are written as
var _(something)
instead of
var_(something)

i recommend keeping them consistent, so as not to get an error.

as well, im typing this without being on gamemaker currently, so sorry if i made a mistake
Okay so I put them as
GML:
var_cpuchoice  instead of
var _cpuchoice
Then it had come up with an error saying
!! Unnecessary expression var_cpuchoice used a statement!!

Then the rest of the statements i've also changed back say unassigned variable var_cpuchoice refrenced

Would you like me to send a pic?
 

Squeegee209

Member
Okay, I think there was a small misunderstanding earlier, but it's fixable.
When I said to make a var_cpuchoice, I meant add it in later. On its own, GameMaker thinks that it's a statement.
A bit near the top, you put a line with just that variable name and nothing else.
Remove that single line, and it should work?
 

MoriMori

Member
Okay, I think there was a small misunderstanding earlier, but it's fixable.
When I said to make a var_cpuchoice, I meant add it in later. On its own, GameMaker thinks that it's a statement.
A bit near the top, you put a line with just that variable name and nothing else.
Remove that single line, and it should work?
Good news it's worked!! but where should I add it now? :) the var_cpuchoice

I also wish to add in the fact their are 3 rounds so is there code to reset to round 2 after you win or loose round 2

Then round 3 if computer wins you go to
rm_gameover and if you win you gp to rm_victory
 

Squeegee209

Member
Okay, glad to know it works!

Here's an idea:

at the beginning of the step event, add this

var_userchoice = 3;

it will make it default to 3
then, in step event, put the code for the "if (user) = ? && (cpu) = ?" thing

add where each "if" where to you in the form of some "var_userpoints"
on each on where you lose, add a point to some sort of "var_cpupoints"

if you don't know how to do this, just try

var_userpoints += 1;

(if cpu, change user to cpu)

while you're adding this, il try to think of some way to go to another room where it works well
 

MoriMori

Member
Good news it's worked!! but where should I add it now? :) the var_cpuchoice

I also wish to add in the fact their are 3 rounds so is there code to reset to round 2 after you win or loose round 2

Then round 3 if computer wins you go to
rm_gameover and if you win you gp to rm_victory
To add onto this rm means room which you probably knew for sure lmao but just incase

But yes I would like 3 rounds to go on, would that be possible and after the th
ird round you either win or loose or if you draw again do another round until win or loose and go to one of the rooms!

Also will the code I inputed before;
GML:
sprite_index =choose (
spr_rock,spr_paper,spr_scissors)
Will this still be needed?
 

MoriMori

Member
Okay, glad to know it works!

Here's an idea:

at the beginning of the step event, add this

var_userchoice = 3;

it will make it default to 3
then, in step event, put the code for the "if (user) = ? && (cpu) = ?" thing

add where each "if" where to you in the form of some "var_userpoints"
on each on where you lose, add a point to some sort of "var_cpupoints"

if you don't know how to do this, just try

var_userpoints += 1;

(if cpu, change user to cpu)

while you're adding this, il try to think of some way to go to another room where it works well
ONE MORE ISSUE TO ADD ON WHEN I LOAD UP THE GAME AND I HAVE OBJ_CARD ON THE MAP THREE OF THEM WHEN I CLICK ON THEM THEY DON'T DO ANYTHING
 

Squeegee209

Member
ok, makes sense

try in step

if var_userchoice = 3 {
sprite_index =choose (
spr_rock,spr_paper,spr_scissors)
} else {
if var_userchoice = 0 && var_cpuchoice = 1 {
var_result = "Win";
}
if var_userchoice = 0 && var_cpuchoice = 2 {
var_result = "Lose";
}
if var_userchoice = 1 && var_cpuchoice = 0 {
var_result = "Lose";
}
if var_userchoice = 1 && var_cpuchoice = 2 {
var_result = "Win";
}
if var_userchoice = 2 && var_cpuchoice = 0 {
var_result = "Win";
}
if var_userchoice = 2 && var_cpuchoice = 1 {
var_result = "Lose";
}
if var_userchoice = var_cpuchoice {
var_result = "Draw"
}
}

remove the choose from the create, keep the userchoice = 3

as for working, reply and il write what to do next
 

Squeegee209

Member
yes, it should work
it's mostly an improvement on what i had already said

if you need help understanding any of the code, just tell me and il explain it a bit more
 

MoriMori

Member
Does this look right to you?

Also what would I input for when they draw?
and also for when I want the room to change after the winner gains three points

Oh my god I could never have got this far without you you're a life saver 😅✋
 

Attachments

MoriMori

Member
Does this look right to you?

Also what would I input for when they draw?
and also for when I want the room to change after the winner gains three points

Oh my god I could never have got this far without you you're a life saver 😅✋
Also uh will it work now when I try and click on the objects on screen? 😯
 

Squeegee209

Member
first of all, try "+= 1" instead of "=+ 1"
not entirely sure if yours works too, though

second, for when the game starts, not in create, add a variable "global.var_round", set it to "global.var_round = 0;"
whenever you win or lose, += 1 for the round like in the points
dont do that for the draws, and the round will loop
do that for the draws and it'll move on without either of the players getting a point
your choice, but that would be how you add it
 

MoriMori

Member
first of all, try "+= 1" instead of "=+ 1"
not entirely sure if yours works too, though

second, for when the game starts, not in create, add a variable "global.var_round", set it to "global.var_round = 0;"
whenever you win or lose, += 1 for the round like in the points
dont do that for the draws, and the round will loop
do that for the draws and it'll move on without either of the players getting a point
your choice, but that would be how you add it
So I put global.var_round =0; underneath var_result ="Draw"
And it says variable var_round only refrenced once.
What do I do?
So you're saying if I don't add it the round will loop until they get a point?

Wou
first of all, try "+= 1" instead of "=+ 1"
not entirely sure if yours works too, though

second, for when the game starts, not in create, add a variable "global.var_round", set it to "global.var_round = 0;"
whenever you win or lose, += 1 for the round like in the points
dont do that for the draws, and the round will loop
do that for the draws and it'll move on without either of the players getting a point
your choice, but that would be how you add it
 

Squeegee209

Member
What I meant was, each time the round ends, the var_round will kick in

if you set it to 0 after a draw, it wont loop, itll reset ALL the rounds
 

Squeegee209

Member
also, sorry, but i forgot

in the section with the IFs, before the IFs, add this to make it work

if sprite_index = spr_rock {
var_userchoice = 1;
}
if sprite_index = spr_paper {
var_userchoice = 0;
}
if sprite_index = spr_scissors {
var_userchoice = 2;
}
 

Squeegee209

Member
the game start event is another event in the "other" section

as for the var_round, technically it's global.var_round, i just forgot to write the global
 

MoriMori

Member
also, sorry, but i forgot

in the section with the IFs, before the IFs, add this to make it work

if sprite_index = spr_rock {
var_userchoice = 1;
}
if sprite_index = spr_paper {
var_userchoice = 0;
}
if sprite_index = spr_scissors {
var_userchoice = 2;
}
So do i add global.var_round = 0; under the points of each if statement? :)
 

MoriMori

Member
Here
yes, after the point parts
Here is my code so far could you check through and see if it's okay?
I don't think it' in the right order but do you have discord by the way I feel like it migjt be easier for communication :)

But if not what should I do next? I want to change the rooms when the player wins do you know how to code that?
 

Attachments

Squeegee209

Member
yes, i have discord

the only thing i see is that you should change the global.var_round = 0 to global.var_round += 1
that way, itl progress
 

MoriMori

Member
yes, i have discord

the only thing i see is that you should change the global.var_round = 0 to global.var_round += 1
that way, itl progress
Oo yay! Try and add mine yuk.i#9571 if not send me yours and i'll add you! :)

Ahh shoot I missed that little plus sign then! ^^;
 
Top