OKay, i have 1 key:value in firebase
hp_current: 1000
I want that when the button is clicked, the value decreases by a given number, for example, by 20 I decided to try it like this
FirebaseDatabase.getInstance().getReference("raids/$raid_squad/").addListenerForSingleValueEvent(AppValueEventListener{
val raid = it.getValue(Raid::class.java)
val currenthp = raid!!.hp_current
val newhp = currenthp - damage
FirebaseDatabase.getInstance().getReference("raids/$raid_squad/hp_current/").setValue(newhp.toInt())})
But the problem appears when 2 or 3 clients simultaneously click on the button and the HP does not decrease for all 3 clicks, but only for 1 of 3 clicks. Because to reduce it, it takes the old value and it turns out that it does not reduce it in any way because of other clients
I'm new to this, please help what ideas do you have?
p.s I have no problems with saving to the database! There is a problem with the fact that a lot of people should be able to just take and decrease 1 and the same value