weewoo5
|
  |
| Joined: 25 Oct 2009 |
| Total Posts: 2281 |
|
|
| 17 Mar 2013 11:11 AM |
This script keeps having w = 2 underlined red, it's stupid because I don't know why and it just says ',' expected near return, which I have no idea what to do about considering I tried putting a , near repeat. Here is the script:
w = 1 Price = math.random(1.00, 2.40) wait() display = Price wait(60) Price = math.random(1.00, 2.40) wait() display = price w = 2 -- This is underlined red!!!! for w = 2 repeat |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 17 Mar 2013 11:18 AM |
2 things: 1) You can't do math.random(1, 2.4) because it returns an integer. Try math.random(10, 24) / 10. 2) What do you mean by "for w = 2 repeat"? That is the line the error is on (Roblox is weird with showing error lines). |
|
|
| Report Abuse |
|
|
weewoo5
|
  |
| Joined: 25 Oct 2009 |
| Total Posts: 2281 |
|
|
| 17 Mar 2013 12:07 PM |
Ugh, I hate how Roblox only shows integers.
And what was my error in that line? |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 17 Mar 2013 12:08 PM |
What do you mean "Roblox only shows integers"?
And the error in "for w = 2 repeat" is that it doesn't make any sense at all. What are you trying to do? |
|
|
| Report Abuse |
|
|
weewoo5
|
  |
| Joined: 25 Oct 2009 |
| Total Posts: 2281 |
|
|
| 17 Mar 2013 01:43 PM |
| I'm trying to make a stock script that updates it's price every 60 seconds. |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 17 Mar 2013 01:45 PM |
while wait(60) do -- stock stuff end |
|
|
| Report Abuse |
|
|
|
| 17 Mar 2013 01:46 PM |
local Stock = function() --Insert_Lua_Here
wait(60) Stock() end
Stock() |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 17 Mar 2013 01:47 PM |
| @not: That's a bad design because it'd cause a stack overflow. |
|
|
| Report Abuse |
|
|
|
| 17 Mar 2013 01:48 PM |
| not really...it's just recursion. |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 17 Mar 2013 01:49 PM |
| But without a base exit case, Lua'd run out of room. It only has limited amount of memory for how many functions it can go into. The iterative approach is better here. |
|
|
| Report Abuse |
|
|
weewoo5
|
  |
| Joined: 25 Oct 2009 |
| Total Posts: 2281 |
|
|
| 17 Mar 2013 02:18 PM |
I made something that works:
Price = math.random(10, 24) j = math.random(-3, 3) Price2 = Price + j print(Price2) wait(60) while wait(60)do wait(60) j = math.random(-3, 3) Price2 = Price + j print(Price2) end |
|
|
| Report Abuse |
|
|
weewoo5
|
  |
| Joined: 25 Oct 2009 |
| Total Posts: 2281 |
|
|
| 17 Mar 2013 04:05 PM |
Made it much, much, much better here:
local Price = math.random(4, 10) local j = math.random(-3, 3) local Price2 = Price + j if Price2 < 1 then local Price2 = 1 elseif Price2 > 0 then do print(Price2) script.Parent.Parent.Name = "Stock Price:" .. " " .. Price2 .. " Currency" wait(30) while wait(30)do wait(30) local j = math.random(-5, 5) Price2 = Price + j if Price2 < 1 then local Price2 = 1 elseif Price2 >0 then do print(Price2) script.Parent.Parent.Name = "Stock Price:" .. " " .. Price2 .. " Currency" stock2 = Price end end end end end |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 17 Mar 2013 04:07 PM |
if Price2 < 1 then local Price2 = 1 elseif ...
wut? What's that local Price2 = 1 doing? |
|
|
| Report Abuse |
|
|
weewoo5
|
  |
| Joined: 25 Oct 2009 |
| Total Posts: 2281 |
|
|
| 17 Mar 2013 04:16 PM |
| This is preventing the Price from going negative or to 0, real stocks can't be that low. |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 17 Mar 2013 04:17 PM |
| But there's a scope problem. |
|
|
| Report Abuse |
|
|
weewoo5
|
  |
| Joined: 25 Oct 2009 |
| Total Posts: 2281 |
|
|
| 18 Mar 2013 02:20 PM |
I perfected it:
l = 0 local Price = math.random(95000, 130000) local j = math.random(-20000, 20000) Price2 = Price + j wait() Stock1 = Price2 + j if Stock1 > 1 then print(Stock1) script.Parent.Parent.Name = "BRK.a:" .. " " .. Stock1 .. " USD" wait(1) while wait(1)do wait(1) local j = math.random(-20000, 20000) Price2 = Price + j wait() Stock1 = Price2 + j if Stock1 < 1 then l = -1 * (Price2 + j) Stock1 = l * .2 wait() print(Stock1) script.Parent.Parent.Name = "BRK.a Price:" .. " " .. Stock1 .. " USD" elseif Stock1 > 0 then print(Stock1) script.Parent.Parent.Name = "BRK.a Price:" .. " " .. Stock1 .. " USD" end end end |
|
|
| Report Abuse |
|
|