• Advertisement
Sign in to follow this  

Logic help...

This topic is 1839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a pool of 30 models I need to keep track of which are active through several levels.

 

Level 1 I need to check which models are active, subtract those from the pool of 30, and instantiate the rest that aren't activated yet.

 

The activatedModels are stored in a comma separated string which is available to each level. When a new model is activated, I simply append it's number to the string and destroy the model. Each unique model has a number 0-29. The "activated" string for activated models looks like "6,1,4,3,19,14,"

 

On Level 2, I load models that have been activated but not the rest. I get the string of activated models from level 1, split it at the commas, and instantiate the models by number. Insantiate model #6, #1, #4, #3, #19, #14, etc

 

So now on level 1, I have 2 arrays, array1 has the entries "6,1,4,3,19,14," array2 has entries 0,1,2,3,...,29,

 

I need to subtract matching entries between array1 and array2, then instantiate the models of the remaining entries, but not instantiate models that are already activated....

 

Any tips for what methods would help are appreciated. Do I loop through and make a comparison between all entries in both arrays, and subtract entries, or loop through and store non matching entries in a 3rd array? I got most of it done as far as parsing the string, adding activated numbers, etc but just not separating out the already activated from the large pool of available models to spawn them on level 1...

Share this post


Link to post
Share on other sites
Advertisement

I dont really know whats your goal, ...but if you just want to keep track of the activated/deactivated models then use a bool array.

Share this post


Link to post
Share on other sites
Before going into that, what are you doing or trying to do that has created this system?

Eh, I guess I can just express my suspicion and concern up front.

If you're looking to render a subset of models then you can just use a boolean property to mark which ones are active and skip rendering on the ones that aren't. Are your models held in their own objects or are they raw data that's being manipulated/used externally?

Also, why are you using strings for this? Edited by Khatharr

Share this post


Link to post
Share on other sites

What is your general objective on this code? 

 

[quote name='lmbarns' timestamp='1357347245' post='5017595']
So now on level 1, I have 2 arrays, array1 has the entries "6,1,4,3,19,14," array2 has entries 0,1,2,3,...,29,
 
I need to subtract matching entries between array1 and array2, then instantiate the models of the remaining entries, but not instantiate models that are already activated....
[/quote]

 

are you trying to add more models as you progres in game? 

Share this post


Link to post
Share on other sites
The OP describes IMHO: From a total of 30 different models a subset is to be picked during the run of level 1. This subset is to be re-used "as-is" during level 2 and perhaps following levels.

So the task is to pick n <= 30 (probably n < 30) models from the original set of 30 models, i.e. selection without putting back.

A solution would be to hold all IDs of still available models in an indexable storage (e.g. the array mentioned in the OP), generate a random integral number in the range [0, length(storage)-1], use that as index into the storage to read out the appropriate ID, remove it from the storage (i.e. in the case of an array by shifting all IDs with greater indices one index before and decrease the length of the storage by 1), and use the picked ID further for remembering and instantiation. Edited by haegarr

Share this post


Link to post
Share on other sites

Thanks for the responses.  I ended up with 2 arrays before coming back here, but should probably rewrite it to use a list and just add/remove the reference from the single list.

 

The array just holds 30 integers, 0-29, of the possible objects. If it's the first time the player loads the game it will load all 30 objects. As the player "activates" them, the number of that object is added to the second array, then I simply sort it, loop through and set that model's reference in the first array to null, then when it loads I simply loop through the first and for each model index that isn't null, instantiate the object.

 

So say i've activated activatedArray[ 5, 3, 8, 9,], then in the other array I go potentialArray[activatedArray[5]] = null, for each of 5,3,8,9.  ...seems to work. Maybe it's slow but it only runs once when the game is loaded only.

 

I am using a string so I can store the entire thing in 1 entry in either memory or xml, then I split it at the commas and int.Parse() it when I read it back into the game...is that really really really slow or just potential for it to mess up? This is for android.

 

Yesterday I got an xml storage working so I might switch to that, but I'm wondering if memory on mobiles is alright to use for storage...can users edit that like they can on a PC? I was under the impression the values stay in memory even if the app is uninstalled on mobile, so it's not likely for a player to delete/edit the values...??

Edited by lmbarns

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement