• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Need Help With Code : Math Game

A

Aidan K-S

Guest
Hello World

I really need help with my code I keep getting error messages and I'm trying to fix it, but I just can't get it to work.

This is just a simple game created in game maker studio. This game is for a school project and I am on a little bit of a schedule so if you can, respond as fast as possible please.

I am trying to create random numbers and then print hem and then find the answer. I was unable to add a box where players can put there answer, but if you can please fix my mistakes and send me an email with the finished code or add it in the comments!


email: [email protected]

Game2.png :
This is the error!

Controller Draw Event.png
Error location!

Controller Create event.png
Controller Create Event

Script Create.png
The script that is called!

If you need anymore info please ask :)

Thank You
:banana:
 

Attachments

TsukaYuriko

☄️
Forum Staff
Moderator
Welcome to the GMC! :)

First things first, you should read our handy guide about how to Q&A to find out the best way to receive help on this community.
 

TheouAegis

Member
The error meand you are adding a real to a string. Your operation is a string ("+", "-", "x"), but your numbers are reals. You need to put string() around global.dif1sum1 and global.dif1sum2.
 
D

dirkinz

Guest
First we need to break down the error message. There are two parts to it. on the top it tells you in plain english where the error happened (in ascending order). If we look at it a little backwards we see the error happened in obj_controller, in it's Draw event, and in the first code block or action of that event.

The second part of the error is a bit harder to read but gives us more info. The first part (where it says DoAdd :: Execution Error) is saying that there was a problem when it tried to add two things together. the second line tells us where it wa in the code when it was trying to add the things together gml_Object_obj_controller_DrawEvent_1 (line 13). The part with the underscores is just a compresed version of what we were looking at in the first paragraph but (line 13) tells us exactly where in the code to look.

so now we know where it was going wrong (line 13 of the draw event) and what was going wrong (it was unable to add something together) lets look at that part of the code
Code:
draw_text(250, 250, global.dif1sum1 + global.dif1sign1 + global.dif1sum2 + global.dif1sign2 + global.dif1sum3 )
we know the issue was with adding so lets look at what it is trying to add together
global.dif1sum1 ~ a number
global.dif1sign1 ~ a string
global.dif1sum2 ~ a number
global.dif1sign2 ~ a string
global.dif1sum3 ~ a number

if we ignore the values you gave them for a moment and just use arbitrary numbers and string this could produce an equation like:

1 + a + 9 + u + 3

I don't know about you but I don't know how to add letters and i don't think the computer does either. Now all of that is inside a draw_text() call so we want to make everything into a string. we can do so with the string() command like so:

Code:
draw_text(250, 250, string(global.dif1sum1) + global.dif1sign1 + string(global.dif1sum2) + global.dif1sign2 + string(global.dif1sum3) )
Another little bit of unrelated advice: when using brackets { } there is a bit of standard notation that isnt required but is helpful for reading code. Rather than leaving them all on the same line you can use indentations to format it. Your code might look a bit like this:

Code:
if(global.gameon .........)
{
     if(global.ready ...........)
     {
          if(global.dif11ng ..........)
          {
               draw_text(250, 25.................)

               if(global.dif11ng ...............)
               {
                    draw_text(250, 25.............)
               }
          }
     }
}
also you can post code directly in your posts by putting [.code] around your code [./code] (minus the periods. i put them there to prevent it from looking like code.)
 
Last edited by a moderator:
A

Aidan K-S

Guest
:)Thank you all for your response I wil try to add all of them to the game and will get back to you if anything happens :D

Welcome to the GMC! :)

First things first, you should read our handy guide about how to Q&A to find out the best way to receive help on this community.
Thank you! This helps;)

I am sorry that I did not read that before posting I will follow these rules in my next post.

I think it would be a good idea if that link popped up and told us to go to it! This way you wouldn't need to comment to us to read it!:D
 
Last edited by a moderator:
A

Aidan K-S

Guest
First we need to break down the error message. There are two parts to it. on the top it tells you in plain english where the error happened (in ascending order). If we look at it a little backwards we see the error happened in obj_controller, in it's Draw event, and in the first code block or action of that event.

The second part of the error is a bit harder to read but gives us more info. The first part (where it says DoAdd :: Execution Error) is saying that there was a problem when it tried to add two things together. the second line tells us where it wa in the code when it was trying to add the things together gml_Object_obj_controller_DrawEvent_1 (line 13). The part with the underscores is just a compresed version of what we were looking at in the first paragraph but (line 13) tells us exactly where in the code to look.

so now we know where it was going wrong (line 13 of the draw event) and what was going wrong (it was unable to add something together) lets look at that part of the code
Code:
draw_text(250, 250, global.dif1sum1 + global.dif1sign1 + global.dif1sum2 + global.dif1sign2 + global.dif1sum3 )
we know the issue was with adding so lets look at what it is trying to add together
global.dif1sum1 ~ a number
global.dif1sign1 ~ a string
global.dif1sum2 ~ a number
global.dif1sign2 ~ a string
global.dif1sum3 ~ a number

if we ignore the values you gave them for a moment and just use arbitrary numbers and string this could produce an equation like:

1 + a + 9 + u + 3

I don't know about you but I don't know how to add letters and i don't think the computer does either. Now all of that is inside a draw_text() call so we want to make everything into a string. we can do so with the string() command like so:

Code:
draw_text(250, 250, string(global.dif1sum1) + global.dif1sign1 + string(global.dif1sum2) + global.dif1sign2 + string(global.dif1sum3) )
Another little bit of unrelated advice: when using brackets { } there is a bit of standard notation that isnt required but is helpful for reading code. Rather than leaving them all on the same line you can use indentations to format it. Your code might look a bit like this:

Code:
if(global.gameon .........)
{
     if(global.ready ...........)
     {
          if(global.dif11ng ..........)
          {
               draw_text(250, 25.................)

               if(global.dif11ng ...............)
               {
                    draw_text(250, 25.............)
               }
          }
     }
}
also you can post code directly in your posts by putting [.code] around your code [./code] (minus the periods. i put them there to prevent it from looking like code.)
I just want to thank you sooooooo much this helped a lot. Thank you for the advise and I hope to see you more often in the GML.:) community.

P.S It worked ;)
 
D

dirkinz

Guest
I've been away a little while but Huzzah! Glad to see you got it fixed. :) Good luck with all your future programs
 
Top