• 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!

GML Help! sprite won't appear on screen SOLVED

MoriMori

Member
Whenever I load up my game despite having

GML:
sprite_index = choose (
spr_card_rock,spr_card_paper,
spr_card_scissors)
To choose a sprite the screen turns black, any solutions?
 

Attachments

Have you already seen if you put the object in the room? or if the object is visible? or if you have a "draw event" you must put "draw_self ();" Or it could also be that you have a "depth" too low but if you want help you will have to provide more information (excuse the quotes, I'm using the google translator)
 

MoriMori

Member
Have you already seen if you put the object in the room? or if the object is visible? or if you have a "draw event" you must put "draw_self ();" Or it could also be that you have a "depth" too low but if you want help you will have to provide more information (excuse the quotes, I'm using the google translator)
Okay to start off with the object is within the room it's clear to see for me :)

Then I don't have a draw event but would it be wise to add one just for this?

What information would you like to know?
 
Okay to start off with the object is within the room it's clear to see for me :)

Then I don't have a draw event but would it be wise to add one just for this?

What information would you like to know?
If the object is visible or not and what the "draw_self ();" It is only necessary if you gave the object a "draw event or draw GUI" although there is probably some conflict with the sprite to draw or its depth, although it would be more useful if I can see the code to see if I can see any errors that may be causing that
 

MoriMori

Member
If the object is visible or not and what the "draw_self ();" It is only necessary if you gave the object a "draw event or draw GUI" although there is probably some conflict with the sprite to draw or its depth, although it would be more useful if I can see the code to see if I can see any errors that may be causing that
I'll send you the code I've inputed here! ^^
 

Attachments

TsukaYuriko

🌠
Forum Staff
Moderator
Please post code as code, not as screenshots. There's no good reason to post screenshots of code.

Are instances of other objects visible, or is it only this one?
 

MoriMori

Member
Please post code as code, not as screenshots. There's no good reason to post screenshots of code.

Are instances of other objects visible, or is it only this one?
It's all visible

If the object is visible or not and what the "draw_self ();" It is only necessary if you gave the object a "draw event or draw GUI" although there is probably some conflict with the sprite to draw or its depth, although it would be more useful if I can see the code to see if I can see any errors that may be causing that
Here is the code not in screenshots my bad
GML:
EVENT;;Game start;                                                                                                                                                                                                                      var_cpupoints = 0;
var_userpoints = 0;
global.var_round = 0

EVENT;;Create;                                                                                                                                                                                                                           
 var_cpuchoice = irandom_range(0,2);
//makes the computer fenerate a random number, or,rock,paper,orscissors and then assign it to said varible

var_userchoice = obj_cards.image_index;
//gets the image_index of the card object and assigns it to var-userchoice

Event; Step
                                                                                                                                                                                                                                                    
 if var_userchoice = 3 {
    
sprite_index =choose (
spr_card_rock,spr_card_paper,spr_card_scissors)
if sprite_index = spr_card_rock {
    var_userchoice = 1;
}
if sprite_index = spr_card_paper {
    var_userchoice = 0;
}
if sprite_index = spr_card_scissors{
    var_userchoice = 2;
}

} else {
if var_userchoice = 0 && var_cpuchoice = 1 {
var_result = "Win";
var_userpoints +=1;
global.var_round += 1;
}
if var_userchoice = 0 && var_cpuchoice = 2 {
var_result = "Lose";
var_cpupoints +=1;
global.var_round += 1;
}
if var_userchoice = 1 && var_cpuchoice = 0 {
var_result = "Lose";
var_cpupoints +=1;
global.var_round += 1;
}
if var_userchoice = 1 && var_cpuchoice = 2 {
var_result = "Win";
var_userpoints +=1;
global.var_round += 1;
}
if var_userchoice = 2 && var_cpuchoice = 0 {
var_result = "Win";
var_userpoints +=1;
global.var_round += 1;
}
if var_userchoice = 2 && var_cpuchoice = 1 {
var_result = "Lose";
var_cpupoints +=1;
global.var_round += 1;
}
if var_userchoice = var_cpuchoice {
var_result = "Draw"
global.var_round += 1;
}                                                                                                                                                                                                                                                                                  }
Please post code as code, not as screenshots. There's no good reason to post screenshots of code.

Are instances of other objects visible, or is it only this one?
My bad, if you look at one of my responses the code should be there to look at :)
 

TsukaYuriko

🌠
Forum Staff
Moderator
Then other sprites wouldn't be "all visible", hence why I asked that question. :)

Since the assignment of the sprite depends on var_userchoice, what is its value when this code runs? Make sure this check passes.
 

MoriMori

Member
Then other sprites wouldn't be "all visible", hence why I asked that question. :)

Since the assignment of the sprite depends on var_userchoice, what is its value when this code runs? Make sure this check passes.
Where would I find this information? I'm not quite sure myself as all the code previously sent is the code I have 😅
 

TsukaYuriko

🌠
Forum Staff
Moderator
Output its value to the console via show_debug_message, or put a breakpoint at that line and step through your code using the debugger.
 

MoriMori

Member
Output its value to the console via show_debug_message, or put a breakpoint at that line and step through your code using the debugger.
Well this is what I got :)
GML:
**.
Entering main loop.
**.
Pause event has been registered for this frame
Pause event has been unregistered
Attempting to set gamepadcount to 0
Not shutting down steam as it is not initialised
Script_Free called

X://windows/Runner.exe DONE (0)
Igor complete.
elapsed time 00:03:00.3245728s for command "C:\ProgramData/GameMakerStudio2/Cache/runtimes\runtime-2.3.1.409/bin/Igor.exe" -j=8 -options="C:\Users\yukik\AppData\Local\GameMakerStudio2\GMS2TEMP\build.bff" -v -- Windows Run started at 01/21/2021 10:58:47
"cmd"  /c subst Z: /d

elapsed time 00:00:00.0893363s for command "cmd" /c subst Z: /d started at 01/21/2021 11:01:47
"cmd"  /c subst Y: /d

elapsed time 00:00:00.0816094s for command "cmd" /c subst Y: /d started at 01/21/2021 11:01:47
"cmd"  /c subst X: /d

elapsed time 00:00:00.0754518s for command "cmd" /c subst X: /d started at 01/21/2021 11:01:48
SUCCESS: Run Program Complete
 
I did this, i hope it works (I didnt tested it and you need to change somethings to make it work in your game properly but i think that it should work)
create event:

GML:
enum Selection // The enum make easy to know what the number mean why you can assign a name to that number
{
    paper = 1,
    rock  = 2,
    scissors = 3,
}

var_userpoints = 0;
global.var_round = 0;

var_result = undefined; //Set the result to undefined

var_cpuchoice = irandom_range(1,3); // Select the material of the cpu

var_userchoice = get_integer("Select one 1 = paper, 2 = rock, scissors = 3",1); //Get the player selection

________________________________________________________________________________________________________________________
step event:
GML:
switch var_cpuchoice //Select the sprite using cpu choise
{
    case Selection.rock:
        #region
            sprite_index = spr_card_rock;
       
            if var_userchoice == Selection.rock
            {
                var_result = "Tie";
            }
            else if var_userchoice == Selection.scissors
            {
                var_result = "Cpu won";
            }
            else if var_userchoice == Selection.paper
            {
                var_result = "You won";
            }
           
        #endregion
    break;
   
    case Selection.paper:
        #region
            sprite_index = spr_card_paper;

            if var_userchoice == Selection.rock
            {
                var_result = "Cpu won";
            }
            else if var_userchoice == Selection.scissors
            {
                var_result = "You won";
            }
            else if var_userchoice == Selection.paper
            {
                var_result = "Tie";
            }
           
        #endregion
    break;
   
    case Selection.scissors:  
        #region
       
            sprite_index = spr_card_scissors;

            if var_userchoice == Selection.rock
            {
                var_result = "You won";
            }
            else if var_userchoice == Selection.scissors
            {
                var_result = "Tie";
            }
            else if var_userchoice == Selection.paper
            {
                var_result = "Cpu won";
            }
           
        #endregion  
    break;
}

global.var_round++;
show_message("The result is:" + string(var_result));
 

MoriMori

Member
I did this, i hope it works (I didnt tested it and you need to change somethings to make it work in your game properly but i think that it should work)
create event:

GML:
enum Selection // The enum make easy to know what the number mean why you can assign a name to that number
{
    paper = 1,
    rock  = 2,
    scissors = 3,
}

var_userpoints = 0;
global.var_round = 0;

var_result = undefined; //Set the result to undefined

var_cpuchoice = irandom_range(1,3); // Select the material of the cpu

var_userchoice = get_integer("Select one 1 = paper, 2 = rock, scissors = 3",1); //Get the player selection

________________________________________________________________________________________________________________________
step event:
GML:
switch var_cpuchoice //Select the sprite using cpu choise
{
    case Selection.rock:
        #region
            sprite_index = spr_card_rock;
      
            if var_userchoice == Selection.rock
            {
                var_result = "Tie";
            }
            else if var_userchoice == Selection.scissors
            {
                var_result = "Cpu won";
            }
            else if var_userchoice == Selection.paper
            {
                var_result = "You won";
            }
          
        #endregion
    break;
  
    case Selection.paper:
        #region
            sprite_index = spr_card_paper;

            if var_userchoice == Selection.rock
            {
                var_result = "Cpu won";
            }
            else if var_userchoice == Selection.scissors
            {
                var_result = "You won";
            }
            else if var_userchoice == Selection.paper
            {
                var_result = "Tie";
            }
          
        #endregion
    break;
  
    case Selection.scissors: 
        #region
      
            sprite_index = spr_card_scissors;

            if var_userchoice == Selection.rock
            {
                var_result = "You won";
            }
            else if var_userchoice == Selection.scissors
            {
                var_result = "Tie";
            }
            else if var_userchoice == Selection.paper
            {
                var_result = "Cpu won";
            }
          
        #endregion 
    break;
}

global.var_round++;
show_message("The result is:" + string(var_result));
Heya just to ask but I want there to be three rounds overall! :) and after the third round they go to either rm_win or rm_game over and if they draw they continue going till someone wins would you be able to help me out with this?

I'm checking if the code works now!

I did this, i hope it works (I didnt tested it and you need to change somethings to make it work in your game properly but i think that it should work)
create event:

GML:
enum Selection // The enum make easy to know what the number mean why you can assign a name to that number
{
    paper = 1,
    rock  = 2,
    scissors = 3,
}

var_userpoints = 0;
global.var_round = 0;

var_result = undefined; //Set the result to undefined

var_cpuchoice = irandom_range(1,3); // Select the material of the cpu

var_userchoice = get_integer("Select one 1 = paper, 2 = rock, scissors = 3",1); //Get the player selection

________________________________________________________________________________________________________________________
step event:
GML:
switch var_cpuchoice //Select the sprite using cpu choise
{
    case Selection.rock:
        #region
            sprite_index = spr_card_rock;
      
            if var_userchoice == Selection.rock
            {
                var_result = "Tie";
            }
            else if var_userchoice == Selection.scissors
            {
                var_result = "Cpu won";
            }
            else if var_userchoice == Selection.paper
            {
                var_result = "You won";
            }
          
        #endregion
    break;
  
    case Selection.paper:
        #region
            sprite_index = spr_card_paper;

            if var_userchoice == Selection.rock
            {
                var_result = "Cpu won";
            }
            else if var_userchoice == Selection.scissors
            {
                var_result = "You won";
            }
            else if var_userchoice == Selection.paper
            {
                var_result = "Tie";
            }
          
        #endregion
    break;
  
    case Selection.scissors: 
        #region
      
            sprite_index = spr_card_scissors;

            if var_userchoice == Selection.rock
            {
                var_result = "You won";
            }
            else if var_userchoice == Selection.scissors
            {
                var_result = "Tie";
            }
            else if var_userchoice == Selection.paper
            {
                var_result = "Cpu won";
            }
          
        #endregion 
    break;
}

global.var_round++;
show_message("The result is:" + string(var_result));
Also i've included the code, but it says
" variable var_userpoints only refrenced once where would I input this varible!" :)
 
You can do something like a object than when you click on im the user choice change instead of use the get_integer() and instead of using the step event you can define the default user choice to - 1 and when you click to one of the object change that to the specific material and after that set a alarm in the cpuobject to check if you won or lose and after that you change the user_choice to - 1 to make it dont upgraded(or still using the step event and in the first line put
GML:
If user_choice == - 1 exit;
)
 

MoriMori

Member
You can do something like a object than when you click on im the user choice change instead of use the get_integer() and instead of using the step event you can define the default user choice to - 1 and when you click to one of the object change that to the specific material and after that set a alarm in the cpuobject to check if you won or lose and after that you change the user_choice to - 1 to make it dont upgraded(or still using the step event and in the first line put
GML:
If user_choice == - 1 exit;
)
Okay so first of all I set
if user choice == -1 exit;
On the first line of the step event correct?
Do I delete anything then?

How do I do the next part then?
 
Okay so first of all I set
if user choice == -1 exit;
On the first line of the step event correct?
Do I delete anything then?

How do I do the next part then?
When you put that in the first line the game will ignore All that happen next so when you change the vale to 1 for ¿rock? It will stop ignoring the step event so when the step event end you set tha vale to - 1 to reset him and now make the object to select paper, rock, scissors come back to set that vale again to other number(I explained well? Im writing this without use google translator)
 

TsukaYuriko

🌠
Forum Staff
Moderator
Oh! How would I change this to three?
You're asking how to change a variable's value when you've done so multiple times in the code you've posted. You do it the same as in all of those cases, variable = value;. So, in this case, var_userchoice = 3;.

I don't think this is the question you meant to ask, though. A better question would be when do you change this to three - because unless you do so, your code will never assign a sprite - and this is a question you will have to answer rather than me, as the code you posted never does this.
 

MoriMori

Member
When you put that in the first line the game will ignore All that happen next so when you change the vale to 1 for ¿rock? It will stop ignoring the step event so when the step event end you set tha vale to - 1 to reset him and now make the object to select paper, rock, scissors come back to set that vale again to other number(I explained well? Im writing this without use google translator)
okay let me type out the code and tell me what needs to be changed/added

create event
GML:
enum Selection // The enum make easy to know what the number mean why you can assign a name to that number
{
    paper = 1,
    rock  = 2,
    scissors = 3,
}

var_userpoints = 0;
global.var_round = 0;

var_result = undefined; //Set the result to undefined

var_cpuchoice = irandom_range(1,3); // Select the material of the cpu

var_userchoice = get_integer("Select one 1 = paper, 2 = rock, scissors = 3",1); //Get the
if what your saying do you want me to change rock to 1?
so would I swap paper and rock?
then the step event
GML:
if user_choice == -1 exit;

switch var_cpuchoice //Select the sprite using cpu choise
{
    case Selection.rock:
        #region
            sprite_index = spr_card_rock;
    
            if var_userchoice == Selection.rock
            {
                var_result = "Tie";
            }
            else if var_userchoice == Selection.scissors
            {
                var_result = "Cpu won";
            }
            else if var_userchoice == Selection.paper
            {
                var_result = "You won";
            }
        
        #endregion
    break;

    case Selection.paper:
        #region
            sprite_index = spr_card_paper;

            if var_userchoice == Selection.rock
            {
                var_result = "Cpu won";
            }
            else if var_userchoice == Selection.scissors
            {
                var_result = "You won";
            }
            else if var_userchoice == Selection.paper
            {
                var_result = "Tie";
            }
        
        #endregion
    break;

    case Selection.scissors:
        #region
    
            sprite_index = spr_card_scissors;

            if var_userchoice == Selection.rock
            {
                var_result = "You won";
            }
            else if var_userchoice == Selection.scissors
            {
                var_result = "Tie";
            }
            else if var_userchoice == Selection.paper
            {
                var_result = "Cpu won";
            }
        
        #endregion
    break;
}

global.var_round++;
show_message("The result is:" + string(var_result));

i'm not quite sure what to input here tho
 

MoriMori

Member
You're asking how to change a variable's value when you've done so multiple times in the code you've posted. You do it the same as in all of those cases, variable = value;. So, in this case, var_userchoice = 3;.

I don't think this is the question you meant to ask, though. A better question would be when do you change this to three - because unless you do so, your code will never assign a sprite - and this is a question you will have to answer rather than me, as the code you posted never does this.
okay so when I want to change the sprites would be when the round restarts so when you first enter the room and when the room restarts for the next round, do you have any suggestions upon how to do this when so I want the sprites to change once you either win, loose or draw the first round and I want the sprites to appear when you enter the room.
I added the
var_userchoice =3;
rather than
var_userchoice = obj_cards.image_index;
was this right?
 

TsukaYuriko

🌠
Forum Staff
Moderator
okay so when I want to change the sprites would be when the round restarts so when you first enter the room and when the room restarts for the next round, do you have any suggestions upon how to do this when so I want the sprites to change once you either win, loose or draw the first round and I want the sprites to appear when you enter the room.
I added the
var_userchoice =3;
rather than
var_userchoice = obj_cards.image_index;
was this right?
It was not necessarily right and not necessarily wrong. It's your code - you wrote it, and you modified it - so you would have to tell me if it's right or not as you are more familiar with it than I am. I didn't tell you to modify it the way you did - I merely answered your question and asked another - so I can't answer that question. You decided that this is how it should be modified, and if you can't back this up with reasons why it should be modified that way, you're essentially just guessing at this point. This won't get you anywhere, and I can't continue providing help if it merely ends up making you guess because I'd be sending you off towards a dead-end by doing so.

var_userchoice depends on obj_cards.image_index according to your code. I'm bound to think that you had a reason to add this dependency, and only you know it, not me, because you haven't stated it and it's not apparent from the code you've posted. Due to this, it may not be very wise to override this, as you would override the original intent behind making it depend on that in the first place, so while, yes, ensuring that it will be 3 will certainly ensure that a sprite will be assigned, it may also end up breaking something else. Might as well just assign a sprite under all circumstances, completely removing the condition, but there's no way for me to know whether that is what you intend because I barely know anything about this game.

If you don't know what this something else is, whether there even is something else that would break as a result of this, why the dependency was there in the first place or why it's okay to overwrite it and make the changes you made to your code, you've successfully programmed yourself into a corner and can't tell what your own code does (and why) anymore. If that's the case, and if these are the questions you find yourself asking (both to yourself and others) as a result of it, it may be best to take a step back and rework the system you have in place, as it has outgrown your ability to comprehend it and the cause and effect reactions modifications to it have. If you continue to try to "make this work", even if you do succeed, you'll be back the next day with yet another problem due to the multitude of layers of cryptic code that you can't make sense of on your own anymore, and that's clearly not the point of this forum.

If you can't make sense of this system anymore, you can't reasonably expect that others will be able to - I gave up on it, for example - and rewriting this from the ground up and making sure that you actually understand what you're doing will build the foundation upon which you can expand with confidence.

Also, this is not a chat, it's a support forum. Limit posts to on-topic essentials and pay attention not to post more than once in a row. I've already merged four of those posts and the rules clearly explain what behavior is acceptable when posting and what isn't - you may wish to revisit them.
 

MoriMori

Member
well this is how one start, nobody born knowing all
haha yeah, I've been really stressed over making this and there really isn't any tutorials on how to make this sort of game there was one like 8 years ago? but the code would be outdated and not worth the hassle really and I'm just looking for someone to help me make this game and this forum has been the best so far but there still it's okay progress

did you look at the code?
 
This is a little guide of how make this game
-obj_card (with the creation code change that one is paper and other scissor and other the rock)
-obj_cpu
1- You enter the room and there is the "obj_card" in its 3 variants (I will call materials to the rock, paper and scissors)
2- You click on some of them and the "user choice" changes to the object's material and an "alarm [0]" is activated in the cpu_object and you make the "obj_card" disappear(you can make it using "deactivate_object(obj_card)")
3-Here you make the "cpu_object" make its selection of material again (as it does in the create event) and change the code you have in the "step event" here so that it runs only when you call the alarm, when the code of the alarm is executed you put "alarm [1] = room_speed / 2"
4-In the event of alarm 1 you put the "sprite_index = -1" to make it not be seen and make the "obj_card" reappear to repeat the process(if you use deactivate_object you will need use activate_object(obj_card)) (if the cpu chooses the same material over and over again put "randomize () in the create event" to make it change the selection it makes)
5- when the "obj_cpu" becomes invisible put an "if" to see if you have reached the 3 rounds and if you have, you will take it to the screen victory or defeat respectively
(I hope it helps you have an idea of how to do it)
 
Last edited:

MoriMori

Member
Whenever I load up my game despite having

GML:
sprite_index = choose (
spr_card_rock,spr_card_paper,
spr_card_scissors)
To choose a sprite the screen turns black, any solutions?
Hii for anyone that needs this in the future the sprite appears on screen once changed from

GML:
var_userchoice 0 to var_userchoice = 3;
 
Top