Im making a cups and balls game where you have 3 cups which will be shuffled and you need to guess under which cup the ball is. im making a simpler version with 2 balls but im immediately running into a problem. I need the cup on the left to move to the right and the cup on the right to move to the left to ''shuffle'' the ball. I could just make it so that they move left and right based on their coordinates but I want to expand the game to 3 or maybe even 4 cups later. How do i go about making this?
#how to select one instance of an object to run code for?
49 messages · Page 1 of 1 (latest)
@full agate I think I would put these into a ds list (lowest to highest xpos)
Then create a 'shuffle' action that randomly selects any 2 cups next to each other (2 entries next to each other in the ds list) and switches them (for example with a transition).
And then just repeat that x amounts of time for your shuffle action.
this would make it so that the cup on the far right and far left cant be switched
also, how do i specify which instances need to Be moved and and where?
So you have two global arrays: one array that's a position array. that stays fixed and are basically slots of where cups should be
And then you have one array that stores the instance_id's of the cup.
And it's a matter of matching up id's with positions
for i=0; i< num_cups-1; i++{
cups[i].x = position[i][0]
cups[i].y = position[i][0]
}
At the start of the game, you can make the cups manually submit their id's and positions into the arrays in their instance creation code
To shuffle, you pick random numbers between 0 and num_cups-1. If they're the same, try again. otherwise, swap those positions id's in the id array, and run the id-position matching game again.
If you're adding more cups mid game, just expand the two arrays and have the new cup register itself to both
whats the function to make them submit their id? and will that id always be the same?
it will juts be id
and the id stays the same until the instance is destroyed yes
obj_cup.id is the id
built in variable, like x and y - should turn green
but lets say i run the game, then close it, then run the game again
hell if you're feeling fancy you can put your own custom id's
then you need a saving system
damn ok now im getting off track i think
so in the slots the objects will request the id of the cup currently inside them
question actually
but if the id is random how can i use the id in code?
are the empty cups different
im planning on making all cups 1 object and if one collides with the ping pong ball, theyll move up if you click on it
ok let's not beat around the bush
what exactly is the game you're tryna make
let's not try to make a cup swapping game if that's not even what you're doing
you have 2 cups, one of which has a ping pong ball under it, they get shuffled, and you have to choose the right one
thats the entire game
my suggestion here was gonna be
if all the empty cups are the same you don't even really need to bother moving them around. Just make the animation of swapping, and test for the ball externally.
like which ball has the cup is an external variable. the ball doesn't exist until you click on the cup
this is why i said that the cups should register itself to the arrays, not the arrays asking the cups
each cup knows it's own id, and so can go
"Hey, my name is [id], and i am cup #3 at position X, Y"
this npc is "unique"
She has her own creation code that sets her sprite and schedule as the convenience_store_clerk, even tho she is obj_npc
And she consistently does what she does, because her id is consistently inst_npc_conveniene_clerk, and that she has the same creation code
ok wait different question
say I use instance_find
and put all 3 cups in an array
and then i can do something with those values
it won't be the same order
don't use instance find. the order is kinda random, cuz it has to do with creation order
so... how do I find instances, always have them in the same order, and have the code know what value the ID is so it can be used for something?
the most reliable is to use creationc ode
explictily code into that instnace that it is #1
in your room editor, right click the instance, and there's a button called creation code
you can run whatever code specific to that instance, and it's like a 2nd create event but only for that instance specificially
Oh you can go like into the room editor and give them an ID?
That’s pretty useful
that's what this is
see how it says obj_npc?
Alright I think I got it now
how do I access the creation code in my code? is it just a string?