|
| 04 Feb 2017 03:36 PM |
so if I have 100 gold then I have 279 gold I want my script to go difference = 179 then essentially lerp between them. Any ideas? Something like 100 200 210 220 .. etc 270 271 272 etc.
Not sure how to go about it though. Also what if I have to add or remove a digit EG from 100 to 10 or from 999 to 1000? |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 04 Feb 2017 03:37 PM |
What? Can you explain some more
|
|
|
| Report Abuse |
|
|
|
| 04 Feb 2017 03:38 PM |
okay, how many steps should the lerp have? (how many loops before the goal is reached?)
|
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 04 Feb 2017 03:41 PM |
local gold = 100
function AddGold(add) local dir goal = goal+add if goal>gold then dir = 1 else dir = 0 end if goal < 0 then goal = 0 end for i = gold,goal,dir gold = i print(gold) wait() end end
AddGold(5) >101 >102 >103 >104 >105
|
|
|
| Report Abuse |
|
|
|
| 04 Feb 2017 03:49 PM |
That'll do it in a linear fashion if I read it correctly.
I don't want it to go from 100 - 101 - 102 - ... 199 - 200, etc
100 - 200 - 210 - 220 - 230 - 240 - 250
basically, for the hundred, ten, one, etc I want it to go between those.
|
|
|
| Report Abuse |
|
|
|
| 04 Feb 2017 03:54 PM |
I suppose I can try to formulate that better.
If I have the numbers 200 and 579
there are 3 differences: 300, 70, 9
I want my text to show these increments. For example,
200 --> 300 --> 400 --> 500 then 500 --> 510 --> 520 --> 530 (repeat until 570) then 570 --> 571 --> 572 --> 573 (repeat until 579) |
|
|
| Report Abuse |
|
|
| |
|
|
| 04 Feb 2017 05:45 PM |
local v1 = 200 local v2 = 579
local total = 0
local dif = v2 - v1
local hundreds = math.floor(dif/100) local tens = math.floor((dif-hundreds)/10) local ones = dif - (hundreds + tens)
for i=1, hundreds, 100 do total = total + i print(total) wait() end for i=1, tens, 10 do total = total + i print(total) wait() end for i=1, ones do total = total + i print(total) wait() end
|
|
|
| Report Abuse |
|
|
|
| 04 Feb 2017 06:34 PM |
| What if the difference is greater than 999? |
|
|
| Report Abuse |
|
|
|
| 04 Feb 2017 07:04 PM |
| --whole numbers only local ### = 1573 ### = ############# local vals = ## local prev = 0 local total = 0 for ####### 1, -1 do local s = i-1 total = total + (vals[i+1] ## nil and vals[i+1] or 0) vals[i] = ############################# - total end for i=1, #vals do print(vals[i]) end |
|
|
| Report Abuse |
|
|
|
| 04 Feb 2017 07:05 PM |
local dif = 1573
dif = tostring(dif)
local vals = {}
local prev = 0
local total = 0
for i=#dif, 1, -1 do local s = i-1 total = total + (vals[i+1] ~= nil and vals[i+1] or 0) vals[i] = math.floor(dif/(10^s))*(10^s) - total end
for i=1, #vals do print(vals[i]) end
|
|
|
| Report Abuse |
|
|
|
| 04 Feb 2017 07:06 PM |
shortened (had one unused variable)
local dif = 1573 dif = tostring(dif) local vals = {}
local total = 0
for i=#dif, 1, -1 do local s = i-1 total = total + (vals[i+1] ~= nil and vals[i+1] or 0) vals[i] = math.floor(dif/(10^s))*(10^s) - total end
for i=1, #vals do print(vals[i]) end
|
|
|
| Report Abuse |
|
|
|
| 05 Feb 2017 07:03 AM |
| Thanks :^) I don't understand it but I can see it works so yay! :p |
|
|
| Report Abuse |
|
|