0
\$\begingroup\$

I'm trying to make a game which requires a random generation of sentence upon pressing spacebar. I've never done anything like this and wanted to give it a shot with whatever knowledge I had.

Whenever spacebar is pressed, "Be something in something." appears. I want the somethings to be randomized.

This what I wrote in the Create event -

global.profession = irandom(2);
global.situation = irandom(2);

And this in the Space event -

draw_set_colour($777777);
draw_set_font(fnt_rpl);

if global.profession = 0{
  global.profession = "a nurse"
}

if global.profession = 1{
  global.profession = "a driver"
}

if global.profession = 2{
  global.profession = "a police officer"
}

if global.situation = 0{
  global.situation = "in a hospital."
}

if global.situation = 1{
  global.situation = "in a car."
}

if global.situation = 2{
  global.situation = "in a police station."
}

draw_text_ext_transformed(200, 500, "Be" + global.profession + global.situation, 20, 800, 1, 1, image_angle);

Room is set to be 1920x1080 and I've added the object in the room. I'm getting no result, not even an error, when I press space.

\$\endgroup\$
  • \$\begingroup\$ Are you placed this object in the room? \$\endgroup\$ – Dmi7ry Oct 17 '16 at 17:58
  • 1
    \$\begingroup\$ BTW, All these randoms/ifs can be changed to next code: Create event: global.profession = choose("a nurse", "a driver, "a police officer"); global.situation = choose("in a hospital.", "in a car.", "in a police station");. And Draw event: draw_set_colour($777777); draw_set_font(fnt_rpl); draw_text_ext_transformed(200, 500, "Be " + global.profession + " " + global.situation + ".", 20, 800, 1, 1, image_angle);. And I not sure that you really need global variables (I don't know, maybe you used it somewhere else). \$\endgroup\$ – Dmi7ry Oct 17 '16 at 18:45
  • \$\begingroup\$ @Dmi7ry thanks for your tip for reducing the lines of code. To answer your question, yes I had put the object in room. I realized that I wasn't using a Draw event and that's what caused the issue. As of now I've done Create and Draw even as per what you had mentioned and copy pasted Create events code to Space event. It did the job. Thanks again. \$\endgroup\$ – Swapnil Rastogi Oct 18 '16 at 14:42
1
\$\begingroup\$

Thanks to a comment by @Dmi7ry, I was able to figure out my mistake. I was wrong at not putting the draw_text inside a Draw event. I changed the press Space event to Draw event while making changes as per advised by @Dmi7ry. Then I made another press Space event and copy pasted the code that was in the Create event. Thanks to @Dmi7ry again.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.