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

Windows I need help with making an object clickable

A

Angel Michnowicz

Guest
There in a object in a game that I am making that the user is supposed to be able to click on. When clicked the object should change the text displayed on another object. How would I go about doing that?
 
A

Angel Michnowicz

Guest
Well, in order to click in something, you need to know two things: If you are clicking and if what you clicked at was the object.
These might be useful for figuring these properties out.

https://docs.yoyogames.com/source/dadiospice/002_reference/objects and instances/instances/instance functions/instance_place.html
https://docs.yoyogames.com/source/dadiospice/002_reference/mouse, keyboard and other controls/mouse input/index.html
I know about those but every time I use those it doesnt work

Add a mouse event to the object.
and what code should be within the event?
 
A

Angel Michnowicz

Guest
Whatever you want to happen the the object is clicked. So, change the text that you want to change.
I dont think your getting what im saying. The text i want to change is in a different object then the one the user clicks on.
 
I assume you draw the text via a draw event for that different object, correct? So then you are using a string for whatever the text is.

Therefore you can save that string as a global variable, e.g. global.objecttext = "Hello world!", you would do this in the create event of that other object.

So in the draw event you would tell it to draw that global variable.

And then in that new object in the mouse click event you add global.objecttext = "Goodbye world!" for example.
 
A

Angel Michnowicz

Guest
I assume you draw the text via a draw event for that different object, correct? So then you are using a string for whatever the text is.

Therefore you can save that string as a global variable, e.g. global.objecttext = "Hello world!", you would do this in the create event of that other object.

So in the draw event you would tell it to draw that global variable.

And then in that new object in the mouse click event you add global.objecttext = "Goodbye world!" for example.
what you said works but only if it isnt an mouse click event. So would there be a way to fix that?
 
A

Angel Michnowicz

Guest
Sorry, I think it needs to be in mouse click pressed event, so that it is permanently triggered once pressed.
I know and I understand that. What im saying is that its not working so could it be something in my code that could be messing that up?
 

Coded Games

Member
I know and I understand that. What im saying is that its not working so could it be something in my code that could be messing that up?
If something isn't working, there is a 99% chance it's your code. Because you haven't posted any of it here, none of us will be able to help you with that.
 

CloseRange

Member
object1:
Code:
/// create event
text = "Hello"
Code:
/// draw_event
draw_text(x, y, text);
object2:
Code:
/// mouse_pressed_event
object1.text = "goodbye"
this is how it should work.
Object 1 has a variable that stores text (this has to be set in the create event, not draw or anything else like that)
then it draws that text.
if you click object 2 (the mouse_pressed_event) it will set object1's text variable to something else
 
A

Angel Michnowicz

Guest
object1:
Code:
/// create event
text = "Hello"
Code:
/// draw_event
draw_text(x, y, text);
object2:
Code:
/// mouse_pressed_event
object1.text = "goodbye"
this is how it should work.
Object 1 has a variable that stores text (this has to be set in the create event, not draw or anything else like that)
then it draws that text.
if you click object 2 (the mouse_pressed_event) it will set object1's text variable to something else
What you said does make sense but for some reason it isnt working
 
A

Angel Michnowicz

Guest
object1:
Code:
/// create event
text = "Hello"
Code:
/// draw_event
draw_text(x, y, text);
object2:
Code:
/// mouse_pressed_event
object1.text = "goodbye"
this is how it should work.
Object 1 has a variable that stores text (this has to be set in the create event, not draw or anything else like that)
then it draws that text.
if you click object 2 (the mouse_pressed_event) it will set object1's text variable to something else
nevermind it worked
 
Top