Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Logic help...


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 lmbarns   Members   -  Reputation: 460

Like
0Likes
Like

Posted 04 January 2013 - 06:54 PM

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...



Sponsor:

#2 Aliii   Members   -  Reputation: 1447

Like
0Likes
Like

Posted 04 January 2013 - 09:44 PM

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.



#3 Khatharr   Crossbones+   -  Reputation: 3031

Like
0Likes
Like

Posted 04 January 2013 - 10:08 PM

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, 04 January 2013 - 10:35 PM.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

#4 Nusakan   Members   -  Reputation: 444

Like
0Likes
Like

Posted 05 January 2013 - 03:06 AM

What is your general objective on this code? 

 

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....

 

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



#5 haegarr   Crossbones+   -  Reputation: 4437

Like
1Likes
Like

Posted 05 January 2013 - 03:59 AM

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, 05 January 2013 - 04:07 AM.


#6 lmbarns   Members   -  Reputation: 460

Like
0Likes
Like

Posted 08 January 2013 - 10:42 AM

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, 08 January 2013 - 10:43 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS