playMaker

Author Topic: Enabling/Disabling Gamobjects in an arraylist [SOLVED]  (Read 3252 times)

Budde88

  • Full Member
  • ***
  • Posts: 165
Enabling/Disabling Gamobjects in an arraylist [SOLVED]
« on: May 27, 2016, 07:43:49 AM »
I have downloaded the arraymaker package into my project.

I need to know how to get a random object in a list to Activate, and for all the others in that list to De-activate at the same time.

Thanks
« Last Edit: May 28, 2016, 09:37:38 AM by Budde88 »

Chizzler

  • Junior Playmaker
  • **
  • Posts: 67
Re: Enabling/Disabling Gamobjects in an arraylist
« Reply #1 on: May 27, 2016, 01:24:56 PM »
First get the size of your Array using "Array count". This gives you a maximum number to pick at random.

Use "Random Int" to select a random Number between 0 and X.

Next use "Array Get" and use the random int as the index number. Now you've selected a random object from your array. You can use the "Activate Game Object" action to activate it.

Then you need to remove that value from the array using the "Array List Remove" action, and the random int (to select the correct index number).

Finally, Loop through the array using Array Get Next, and use the Activate Game Object Action to Disable the objects.

Budde88

  • Full Member
  • ***
  • Posts: 165
Re: Enabling/Disabling Gamobjects in an arraylist
« Reply #2 on: May 27, 2016, 03:12:48 PM »
Hey thanks for the reply,

I may have a few more questions for you later on about this if it doesn't work,
But for now just one :)

In the Array Count, do I set the to the same number I am using to index or must I set that to an INT with a high number?

Thanks

Chizzler

  • Junior Playmaker
  • **
  • Posts: 67
Re: Enabling/Disabling Gamobjects in an arraylist
« Reply #3 on: May 27, 2016, 03:44:46 PM »
The array count is just returning the size of your array. You don't want to pick a random number outside of your array, so you need to know the range your random integer can be from.

You don't need to store it in a seperate variable though if that's what your asking, so you can use the same variable to store your random number.

Budde88

  • Full Member
  • ***
  • Posts: 165
Re: Enabling/Disabling Gamobjects in an arraylist
« Reply #4 on: May 27, 2016, 04:29:34 PM »
Here is an image detailing the steps I am taking,
Maybe you could see visually where I am going wrong.

Or if anyone else would chip in too, that would be really great.

Chizzler

  • Junior Playmaker
  • **
  • Posts: 67
Re: Enabling/Disabling Gamobjects in an arraylist
« Reply #5 on: May 27, 2016, 05:20:48 PM »
Sorry,   "Array List Remove" Should be "Array List Remove At"  and use your random number to select the index.

Also you're restricting your "Random Int" to a min of 0 and a max of 0. Use the Count Variable as your max, or change the Array Count action to store the result as "Right Index"
« Last Edit: May 27, 2016, 05:27:19 PM by Chizzler »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Enabling/Disabling Gamobjects in an arraylist
« Reply #6 on: May 27, 2016, 08:12:11 PM »
Hi,
Maybe it can be done easier depending on your project.
Is your list a premade list or are you adding gameobjects to that list during runtime?

if premade and nothing wil be added/removed during runtime you do not need to use array list count.

Do the gameobjects need to stay in that list after activating/deactivating?
if it needs to stay maybe you can better do it like this :

get a "random int", then use "array list get next" and get the index variable,
next step use an "int compare" and compare the random int and the index variable,
if it is equal enable if its not disable and then loop back to array list get next

if you want to enable more than one you can set it up like this :

Make sure to enable "Action Sequence mode" (right click in a state and select it)


Budde88

  • Full Member
  • ***
  • Posts: 165
Re: Enabling/Disabling Gamobjects in an arraylist
« Reply #7 on: May 28, 2016, 04:58:03 AM »
Hey guys thanks again for the replies,

I think it's best I describe a specific scenario in which I need these arrays to work, I spent many hours trying to implement both of your ways, but I could not find any consistency, and this game unfortunately requires absolute consistency.

I attached an image explaining a scenario of events that I need to achieve, at least this way you can see exactly how I need things implemented.

Thanks, and sorry to be such a pest.
« Last Edit: May 28, 2016, 06:54:15 AM by Budde88 »

Budde88

  • Full Member
  • ***
  • Posts: 165
Re: Enabling/Disabling Gamobjects in an arraylist
« Reply #8 on: May 28, 2016, 09:37:08 AM »
I was able to get it working, so I will mark this as solved.

For anyone interested, I created 2 index variables (current index & previous index).

I logged a current index, and then ran through the same script again, except I added an action that set the previous index to current index.
I then ran a check (compare int) to make sure the indexs never matched so I would always have a new object Activating thus always having the previous object De-activate.

I will post an image if anyone is interested.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Enabling/Disabling Gamobjects in an arraylist [SOLVED]
« Reply #9 on: May 28, 2016, 11:09:48 AM »
Hi,
I made a sample yesterday not using array's i was planning to make a video today but i have no time at the moment.
But i will add the sample so you can check it out.

Budde88

  • Full Member
  • ***
  • Posts: 165
Re: Enabling/Disabling Gamobjects in an arraylist [SOLVED]
« Reply #10 on: May 28, 2016, 11:13:40 AM »
Thanks Dino, will check it out.
I have to start learning about Arrays, and I thought this would be a good time.
I have it all up and running thanks to you guys for helping me out.