|
Anyone know why this executes once, but messes up after executing "--do stuff".
I think it's a logical error but it's really bugging me that I can't find it e.e
a = {1, 2, 3}
b = {2, 3, 4}
c = {3, 1}
d = {4, 2}
table1 = a
function whichTable(in)
local listOfNumbers = {1, 2, 3, 4}
local listOfLetters = {a, b, c, d}
local x = 1
local b = true
while b == true do
if in == listOfNumbers[x] then
out = listOfLetters[x]
b = false
else
x = x + 1
end
end
return out
end
while true do
number = table1[math.random(2, #table1)]
--do stuff
table1 = nil
table1 = whichTable(number)
wait(0.1)
end
~CrayBray |
|
|
Oops, as this is a simplified version overlooked the fact that there's two b's, one being a variable one being a table e.e
Ignore that mistake in the above code.
~CrayBray |
|
|
I can pay in rbx if someone wants some easy cash.
~CrayBray |
|
IntequeJoin Date: 2012-12-21 Post Count: 68 |
since table1 equals nil, it doesn't exist anymore. |
|
|
Got it working magically.
Might've been something to do with
math.random(2, #table)
Can you not do this? 0.o
~CrayBray |
|
|
whichTable() is supposed to reassign table1, of which I believe it does.
~CrayBray |
|
IntequeJoin Date: 2012-12-21 Post Count: 68 |
that also works |
|
|
Yeah, so I'm just sitting here confused rn.
At least it works.
~CrayBray |
|
|
If anyone wants the robux tell me why the following code works but the code in the original post does not 0.o pOne = {game.Workspace.p2.Position}
pTwo = {game.Workspace.p3.Position, game.Workspace.p4.Position}
pThree = {game.Workspace.p1.Position}
pFour = {game.Workspace.p2.Position}
cPoint = pOne
function whatPoint(inPoint)
local PointLoc = {game.Workspace.p1.Position, game.Workspace.p2.Position, game.Workspace.p3.Position, game.Workspace.p4.Position}
local PointName = {pOne, pTwo, pThree, pFour}
local x = 1
local b = true
while b == true do
if inPoint == PointLoc[x] then
outPoint = PointName[x]
b = false
else
x = x + 1
end
wait(0.1)
end
return outPoint
end
while true do
nPoint = cPoint[math.random(1, #cPoint)]
path = game:GetService("PathfindingService"):ComputeRawPathAsync(cPoint[1], nPoint, 200)
local points = path:GetPointCoordinates()
for i = 1,#points do
game.Workspace.Farmer.Humanoid:MoveTo(points[i])
game.Workspace.Farmer.Humanoid.MoveToFinished:wait()
end
cPoint = nil
cPoint = whatPoint(nPoint)
wait(0.1)
end
~CrayBray |
|
IntequeJoin Date: 2012-12-21 Post Count: 68 |
I see what you did wrong. You made math.random also execute table1, but since you did number = table1[math.random(2, #table1)] you made it execute table1 twice. if you still don't get it, you already wrote "table1" in number, executing it twice when you wrote table1 = whichTable(number), number already contains table1 in it, so it just comes back with an error |
|
IntequeJoin Date: 2012-12-21 Post Count: 68 |
second code doesn't contain math.random. also, i noticed something in the 1st code, math.random doesn't actually work with tables lol. |
|
IntequeJoin Date: 2012-12-21 Post Count: 68 |
math.randomseed(tick() is what you forgot to put first in the first code. if you just do math.random, it assumes you are printing it |
|
OzzyFinJoin Date: 2011-06-07 Post Count: 3600 |
"math.randomseed(tick() is what you forgot to put first in the first code. if you just do math.random, it assumes you are printing it"
no
definitely a no |
|
|
Hmmm.... Ok I guess. Gonna have to do some research into that 0.o
~CrayBray |
|