Trying to achieve two simple effect that is common in casual games.

Thanks for the incremental score code and I could integrate it into my game with no problem but problem is, the rate that the score increases is slow, I would like to have the same effect but happen very fast.

Like in Fruit Ninja, when score increases it gets increamented very fast. I set my FPS of my app to 60, but it’s still very slow and lame. [import]uid: 206803 topic_id: 35718 reply_id: 144797[/import]

Change the increment-by value to something higher than one until you get effect you want. It’s math: 60fps, +1 per frame will result in an increase of 60 points per second. +2 per frame = 120 points per second, etc.
[import]uid: 31041 topic_id: 35718 reply_id: 144798[/import]

edited.

(Why can’t we delete our posts?!) [import]uid: 206803 topic_id: 35718 reply_id: 144803[/import]

Thanks for the incremental score code and I could integrate it into my game with no problem but problem is, the rate that the score increases is slow, I would like to have the same effect but happen very fast.

Like in Fruit Ninja, when score increases it gets increamented very fast. I set my FPS of my app to 60, but it’s still very slow and lame. [import]uid: 206803 topic_id: 35718 reply_id: 144797[/import]

Change the increment-by value to something higher than one until you get effect you want. It’s math: 60fps, +1 per frame will result in an increase of 60 points per second. +2 per frame = 120 points per second, etc.
[import]uid: 31041 topic_id: 35718 reply_id: 144798[/import]

edited.

(Why can’t we delete our posts?!) [import]uid: 206803 topic_id: 35718 reply_id: 144803[/import]

Rob,

Thanks, for your reply. One question, when I want to remove and completely delete a display image I call removeSelf on it and then put nil into it but you did this:

[lua]display.remove(target)
target = nil
[/lua]

May I ask what is the difference between display.remove(target) with calling removeSelf() on a display image?

Thanks in advance,
and may the Force be with you. [import]uid: 206803 topic_id: 35718 reply_id: 145450[/import]

display.remove(object) basically does a nil test to make sure object isn’t nil before removing it. Basically it does:

if object then  
 object:removeSelf()  
end  

It saves you from having to write that if statement over and over again. [import]uid: 199310 topic_id: 35718 reply_id: 145451[/import]

It’s slightly safer. object:removeSelf() will cause a run time error of object==nil. display.remove(object) will continue silently if object==nil.

Setting target=nil decreases the reference count for the target, triggering garbage collection when appropriate. Even if you use removeSelf(), I believe it’s still good practice to set the object to nil when you’re done with it.

[import]uid: 31041 topic_id: 35718 reply_id: 145452[/import]

While we are at it, what if a display object is added to a table. Does calling display.remove and setting nil to it enough or I have to remove it from that table as well?

I think we have to because that array has it’s reference and doesn’t allow reference count to be zero, right? [import]uid: 206803 topic_id: 35718 reply_id: 145481[/import]

If you do:

mytable[5] = nil  

after removing the object, then the reference count on the memory will drop by one and if it’s not in use, it gets freed. You don’t need to nil the whole table.

Just keep in mind that if you nil an entry that’s using a numeric index and there are entries higher than what your nilling (5 in my example) then the # operator will stop where you nil’ed and won’t count higher values. There is a table function that will return the true count.
[import]uid: 199310 topic_id: 35718 reply_id: 145591[/import]

Thanks for the incremental score code and I could integrate it into my game with no problem but problem is, the rate that the score increases is slow, I would like to have the same effect but happen very fast.

Like in Fruit Ninja, when score increases it gets increamented very fast. I set my FPS of my app to 60, but it’s still very slow and lame. [import]uid: 206803 topic_id: 35718 reply_id: 144797[/import]

Change the increment-by value to something higher than one until you get effect you want. It’s math: 60fps, +1 per frame will result in an increase of 60 points per second. +2 per frame = 120 points per second, etc.
[import]uid: 31041 topic_id: 35718 reply_id: 144798[/import]

edited.

(Why can’t we delete our posts?!) [import]uid: 206803 topic_id: 35718 reply_id: 144803[/import]

[quote=“rob,post:31,topic:310515”]

If you do:

mytable[5] = nil

after removing the object, then the reference count on the memory will drop by one and if it’s not in use, it gets freed. You don’t need to nil the whole table. Just keep in mind that if you nil an entry that’s using a numeric index and there are entries higher than what your nilling (5 in my example) then the # operator will stop where you nil’ed and won’t count higher values. There is a table function that will return the true count.
[import]uid: 199310 topic_id: 35718 reply_id: 145591[/import] [/quote]

 

Rob would you mind expanding on this a little bit?  I am working on something where I nil something out from a table and am having a problem when trying to reinsert objects into the table.  What is the function you talk about that returns the true count?  Is there a way to sort of reset the index or something so that the higher values can be counted?

 

Sorry if I didn’t explain my questions well, i’m not too knowledgeable on the subject.   

The function is table.maxn()

 

In the example above if you nil out a middle entry in the array, say entry #3, you can just assign your data back to array[3] = something to repopulate that cell.   If your array contains simple data (not display objects, sounds, or other large things), you can simply overwrite the cells as necessary.

 

Maybe if you post some code inside of [lua] and [/lua] tags (without spaces) I might understand your needs better.

Hmmm, I think the best way would be maybe to tell you what i’m trying to do conceptually because that is probably where my problem lies.  

 

I am creating a card game that shuffles 52 cards and inserts them as display objects into a table.  Each hand some cards are dealt and as each one is dealt they are inserted into one of two groups.  At the end of the hand the cards are removed via:

 

    for i = playerGroup.numChildren, 1, -1 do          local child = playerGroup[i]         child.parent:remove(child)         child = nil     end      for i = dealerGroup.numChildren, 1, -1 do          local child = dealerGroup[i]         child.parent:remove(child)         child = nil     end  

 

Now, the problem falls when I get to the end of the deck and have to reshuffle the cards, and try to restart the same process as before.  

 

function reShuffle()     if counter \>= 10 then          setupCards()         backs()         counter = 0         playerGroup:toFront()         dealerGroup:toFront()     end  end   

 

So this reshuffles the cards and should basically start with a fresh deck.  The counter is reset and the next cards will be dealt from the first index of the table.  I believe the problem is happening when the cards are being dealt this time they are trying to be reinserted to the same display group as before (I just realized after typing all of that i’m not having a problem with the array but instead the display group… oops maybe you can still help anyways).  Then I get this error:

 

 

2/main.lua:197: bad argument #-2 to ‘insert’ (Proxy expected, got nil)

 

at the line where I am trying to reinsert the card display object into the display group via:

playerGroup:insert(cardTable[cardVal[counter]])  

 

Hope I explained this well enough… any ideas where I might be going wrong?

 

Rob,

Thanks, for your reply. One question, when I want to remove and completely delete a display image I call removeSelf on it and then put nil into it but you did this:

[lua]display.remove(target)
target = nil
[/lua]

May I ask what is the difference between display.remove(target) with calling removeSelf() on a display image?

Thanks in advance,
and may the Force be with you. [import]uid: 206803 topic_id: 35718 reply_id: 145450[/import]

display.remove(object) basically does a nil test to make sure object isn’t nil before removing it. Basically it does:

if object then  
 object:removeSelf()  
end  

It saves you from having to write that if statement over and over again. [import]uid: 199310 topic_id: 35718 reply_id: 145451[/import]

It’s slightly safer. object:removeSelf() will cause a run time error of object==nil. display.remove(object) will continue silently if object==nil.

Setting target=nil decreases the reference count for the target, triggering garbage collection when appropriate. Even if you use removeSelf(), I believe it’s still good practice to set the object to nil when you’re done with it.

[import]uid: 31041 topic_id: 35718 reply_id: 145452[/import]