❔ Getting The number when it goes over 100?

Hi, ive been trying to learn c# for a few weeks and ive ran into a problem and cant properly word it to search google with, i have 2 objects where i can walk into them and they give points, the points value is 70 and everytime points go to 100, it resets the points back to 0 which is kinda as intended? Im sure youve lost many brain cells trying to read this but my problem is that i want the value to be 70 but when i pick another drop back up i dont want it to go to 0 but to go to 40...? if no one understands this pls lmk, ill try give it another go XD I Do apologise.
19 Replies
TheRanger
TheRanger2y ago
show what you tried
railedfrombehind
railedfrombehindOP2y ago
TheRanger
TheRanger2y ago
btw levelBar.Value == 100f || levelBar.value > 100f can be shortened to levelBar.Value >= 100f
railedfrombehind
railedfrombehindOP2y ago
agh, i see! thank you 🙂
TheRanger
TheRanger2y ago
so if u got 140 points, u want it to reset to 40 for example?
railedfrombehind
railedfrombehindOP2y ago
yes, basically.
MODiX
MODiX2y ago
TheRanger#3357
REPL Result: Success
140 % 100
140 % 100
Result: int
40
40
Compile: 262.672ms | Execution: 21.633ms | React with ❌ to remove this embed.
TheRanger
TheRanger2y ago
use the % operator in ur case
levelBar.value = levelBar.value % 100;
levelBar.value %= 100; // can also be written this way
levelBar.value = levelBar.value - 100; // can also be subtracted
levelBar.value = levelBar.value % 100;
levelBar.value %= 100; // can also be written this way
levelBar.value = levelBar.value - 100; // can also be subtracted
railedfrombehind
railedfrombehindOP2y ago
Thanks for your help! im not sure if im not understanding how to use it or im just being seriously stupid? but... it returns 0?
TheRanger
TheRanger2y ago
well if it returned 0 it means originally the value was 100
railedfrombehind
railedfrombehindOP2y ago
it starts at 0 and jumps in 70s.
TheRanger
TheRanger2y ago
try debugging the value before you apply the % operator on it
railedfrombehind
railedfrombehindOP2y ago
starts at 0, goes to 70 then back to 0
TheRanger
TheRanger2y ago
u sure? show a screenshot of ur code with the debug messages do u have a debug.Log somewhere else that prints the value?
railedfrombehind
railedfrombehindOP2y ago
i have it in Update()
TheRanger
TheRanger2y ago
it probably called the debug.Log from Update() not the one in checkLevel() do something like Debug.Log("from checkLevel: " + levelBar.value); to indicate that this code is being called from that method i can guess whats going on
railedfrombehind
railedfrombehindOP2y ago
ohhhhhhhhhhhh goddamn im stupid im sorry man, the values are coming from a slider with the max number being 100...
TheRanger
TheRanger2y ago
i doubt the if condition in the checkLevel method will ever be satisfied
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server