generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Can't find the problem in this...

Previous Thread :: Next Thread 
weewoo5 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
17 Mar 2013 01:45 PM
while wait(60) do
-- stock stuff
end
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
17 Mar 2013 01:46 PM
local Stock = function()
--Insert_Lua_Here

wait(60)
Stock()
end

Stock()
Report Abuse
Dr01d3k4 is not online. 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
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
17 Mar 2013 01:48 PM
not really...it's just recursion.
Report Abuse
Dr01d3k4 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
17 Mar 2013 04:17 PM
But there's a scope problem.
Report Abuse
weewoo5 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image