Hello all, I’m new to the forums, so forgive me if this has already been answered; I searched and didn’t find anything about this problem.
I’m not very good at programming really, and I’ve been trying to randomly show/unhide one out of four objects at random, but only one time for each object. Like, for example, when my event triggers one of those four objects to become visible at random, the next time that event is triggered, I want one of the remaining four objects to become visible, not the one that has already become visible. Does that make any sense? LOL
I’d really like it if I could do this without calling a C++ script, because that’s just waaaaay over my head.
If anyone knows how to do this using events, I’d love an example file so that I can use it for future reference!
That’s should be what you want:
ShowAtRandom.zip (4.72 KB)
You could also use an Object’s variable, that you set on 1 when the object has been shown, then randomly select another object which variable is equal to zero.
I’ve discovered object’s variables are really useful to keep track of each object state during the scene.
Thanks for the quick replies!
4ian ~ Thank you, 4ian, this will be useful! However, I have four different objects, so this doesn’t seem like it will work for what I’m trying to do currently.
Let me try to be more specific:
These are the objects I have: Object_1, Object_2, Object_3, and Object_4. I’m using the gem images so I can tell them apart easily.
Now, when I press a key, I want one of those objects to become visible, and then when I press the key again, I want a different one to become visible at random, never choosing the same one twice.
Thanks again, 4ian. If I’m still being confusing, let me know.
mtarzaim ~ Thanks! I loooove variables. LOL I’m actually doing something like what you’ve suggested already, but it’s still not as functional as I’d like. What I’ve done is set up a global variable that is chosen at random (default value is 0 when the game starts, and then I use a trigger and make the value Random(3)+1 with each of my objects reacting to one of the resulting numbers), and then I have object variables for each object that I named “visible”; after the object is made visible, the variable is set to 1 so that when my global variable hits that object’s number again, it will then pick another number using the Random(3)+1 function. The problem with this is that my global variable still chooses objects that have already been made visible so that it has to continuously roll again till it finds one that hasn’t been made visible, and I’m afraid there could end up being a delay because of this since I plan on putting more objects in eventually…
You can create a group called “ObjectsToBeShown”.
In this group, add your four objects ( Object_1, Object_2, Object_3, and Object_4 ).
Then you can uses exactly the same events as I did in the example: Just replace “Object” by “ObjectsToBeShown”.
Groups are used to apply the same events to different objects: They can be used to avoid creating the same events for multiple objects, and here we use them to create a “semantic link” between the objects.
Thank you very much! I didn’t know how to use groups. I’ll try that out when I get the chance!
Just on a side note, keep up the excellent work with Game Develop; I love this program.
Edit: It worked! Thanks again!
Just out of curiosity, how did you know about Game Develop?
Back in 2009 while I was still a MOD on Game Jolt, I was searching Google for alternatives to Construct Classic and eventually found Game Develop, though I wasn’t quite ready to start using the program at the time. I’m the one that posted this topic: gamejolt.com/community/forums/to … velop/629/
I’ve kept my eye on the progress you’ve made since then. Game Develop has really come a long way.