Nat always 0 on update

So I have 2 functions, one which gets a list of team values and one which updates them:

image

When I call the function that gets the team value I get the expected result, principal ids and team values:

So the code that works to get the team value is here:

And the code that doesn’t work is really just an extension of this, to update the bank balance:

With this line having updated every team to a bank balance of 0:
image

Any help appreciated.

It’s not really clear what doesn’t work. You should probably put that repeating code in a function.
The second screenshot doesn’t show what happens with ‘ut’. Are you placing it back inside the Hashmap? Are you calling the updateTeamValueInfo inside update call or query.

So yeah I get the code isn’t great, I’m just trying to fix a bug that has come from a rule change I implemented in my gameplay logic.

Here is the final bit where I map to the fantasy team.

I call the function straight from my main canister and can be done from the candid ui:

image

It’s not a query function…

So what doesn’t work is that every team has a bank balance of 0 but they all have varying team values.

It’s almost like the subtraction is always resulting in zero.

1 Like

Ok so I checked my backup of my data from earlier and everyone had a bank balance of zero so it isn’t that this function is setting them to zero, it is as you suspected that the change isn’t saving.

Oh, well, I didn’t understand the problem in full, but I’m glad I could be of some help :smiley:
I assume Hashmap is from Motoko base. If your fantasyTeams is stable var and updatedFantasyTeams is a Class - that may be the problem. (But probably not)

Here is my definition of fantasy teams:

Yeah I’m not sure why I am unable to just replace it.

So we have a class with private var with another class instance and the functions of the first class can’t replace that var. You can isolate it in Motoko playground and see if that’s the problem and I guess it will be a bug then?
Or it may be that the function you use to see the changes is bad.

Recently had a bug like this
let some = { another with bankbalance = 123 }
assuming another has default values. Motoko didn’t typecheck properties when ‘with’ was used. And in this case it should of been bankBalance. Probably not your case, just mentioning it anyway.

Ok so the function I was using to get the bank balances as a check was wrong.