I am trying to make a game in which you can click a button in one frame and it will create an object in another.
How can I do this?
Printable View
I am trying to make a game in which you can click a button in one frame and it will create an object in another.
How can I do this?
oh there is a challenge, I'll post an example soon. Not home yet :D
User clicks button:
-> set global value a to 1
Next frame
Start of frame
+ Global value a = 1:
-> create object
the global value way works, but is there a way that it will take the number of times that the button is clicked and make that much objects?
Also, is there a way to make it create the object anywhere in the area instead of just at a certain location?
One problem with the global value way: If I switch frames then go back, the object gets deleted.
I tried a way to get the object to appear anywhere:
I put an Active moving around the screen invisible.
I set it to create the object wherever the Active is.
The problem is, It restarts the movement every time I go to that frame, so it does not do anything useful.
User clicks button:
-> add 1 to global value a
Next frame
Start of frame
-> Start Loop "create" times global value a
On Loop "create"
-> create object
Anywhere as in a random location or someplace specified by the user?
On Loop "create"
-> create object
-> set object X to Random(Frame Width)
-> set object Y to Random(Frame Height)
It sounds strange that the global value would reset when jumping between frames.
I changed the settings so that the object will appear where the mouse pointer is when I click. (Not immediately once this frame opens)
But, the object still disappears whenever I switch frames.
I set it to reset the value when I create the object.
So, after the object has been created once you want it to reappear at its last position upon leaving and re-entering the frame? That won't happen automatically. Everything in a frame is reset when you leave it and only global values are stored in memory. The object only appears when global value A is greater than 0. Since you reset that global value, the object won't appear again.
I'd use an array to store information between frames, but it can be fairly complicated. Look around for some examples or wait for sparckman's example which I'm sure will be helpful! :)
I would use an INI file, array, or the Named Variable Object to store the information between frames, since it sounds like this could be happening a lot. At the start of a frame, run a fast loop to check for objects to dynamically create. Under the fast loop, you'd have checks for each object and their position. The nice thing about the Named Variable Object is that you can give all your values names like Alterable Values, and they're unlimited. However, I think it's only compatible with the Windows runtime. Anyway, whichever way you go, you'll basically be looking to save the object's existence and position in RAM or in an external file (or both), and then check at the start of a frame for the conditions of its existence to be true.
This is an attachment MFA of the part of the game.
(This does not contain the whole frames, only the parts needed.)
(NOTE: Opened in CF2.5)