LuaWeaver wrote:I am working on Connect 4, and I ran into a strange error. If you change the size of the grid, the size of the pieces change to allow it to still fit snug. I have that down and working. But when I try to position these, I keep running into errors. I came up with a formula to find a scaled size, and now I try to make it so it positions it next to the old one by multiplying by using a for loop value -1. So, it looks like this.
for i=1, 8 do
for h=1, 8 do
local piece=board[i][h]
if piece~=0 then
love.graphics.drawq(piece, size, 600*(1/selected*2)*(h-1), 600*(1/selected*2)*(i-1), 0, 1/selected*2, i/selected*2, 0, 0)
end
end
end
In theory, this should work. When I tried it, nothing appeared on the screen. This is obviously not a table error, because when I used this code,
for i=1, 8 do
for h=1, 8 do
local piece=board[i][h]
if piece~=0 then
love.graphics.drawq(piece, size, 0, 0, 0, 1/selected*2, 1/selected*2, 0, 0) --Note to self, add positioning equation
end
end
end
it showed the image. Why won't this work? Oh, and yes, I do comment myself notes to self.
Change "love.graphics.drawq" to "print" and compare the numbers. Is this what you wanted?
I don't know how you want it to look like, but this kind of works:
Jasoco wrote:That's why I've made it a habit to put all my calculations in parenthesis ahead of time to avoid any potential misordered calculations.
And yes, I think I just made up a word.
Also, there was just recently a thread at NeoGAF about whether 48 / 2 (9 + 3) equalled 2 or 288. When the civil war was over, 288 won, but it showed how many calculators, apps and people (Spotlight in OS X included) calculated it as 2 by doing the multiplication first (i.e. 2 times 12 into 48 being 24 into 48 being 2 instead of 24 times 12 being 288.). So everyone threw their back packs at the stupid kids.
Ha ha! That's funny. I can't believe how many don't know their order of operations! I was taught this:
Exactly. That's how I was taught. In that order. P E M D A S.
But, wouldn't that mean 2 is correct? Because it does the Parenthesis first. 9+3=12. Then the multiplication. 2*12=24. Then the division. 48/24=2.
2 is correct if you follow PEMDAS. Isn't it? You only get 288 if you divide 48 by 2 first then multiply that by 12. But 48/2 doesn't have parenthesis, and multiplication comes first. So 2 is correct!
Of course, my school also taught me I before E except after C then stopped there. So I went through life spelling Cashier wrong. Cashier. Cashier. Stupid POS private school.
Jasoco wrote:2 is correct if you follow PEMDAS. Isn't it? You only get 288 if you divide 48 by 2 first then multiply that by 12. But 48/2 doesn't have parenthesis, and multiplication comes first. So 2 is correct!
It was Parachute Expert My Dear Aunt Sally for me. However, it was stated clearly that MD and AS are on the same level. So in English it would sort be like this:
Jasoco wrote:But, wouldn't that mean 2 is correct? Because it does the Parenthesis first. 9+3=12. Then the multiplication. 2*12=24. Then the division. 48/24=2.
\[ 48 / 2 * (9 + 3) = \frac{48}{2}\cdot (9 + 3) = \frac{48 \cdot (9 + 3)}{2} = 48 \cdot \frac{9 + 3}{2} = 48 \cdot (9 + 3) \cdot \frac{1}{2} \]
It would be 2 if there were paranthesis around the 2 * (9+3).
Think of dividing as multiplying with a fraction: \( 48 \cdot (9 + 3) \cdot \frac{1}{2} = 48 \cdot (9 + 3) \cdot 0.5 \). This is the same as thinking of subtraction as adding a negative number: \( 5 - 3 = -3 + 5 \).
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.
Indeed there are (and there's actually more), although we're talking about maths in general here, not just Lua.
ivan wrote:8. Assignment (=)
Technically = isn't an operator in Lua, and it's actually not in the table of precedence in Programming in Lua. I found this out when I tried to do multiple assignment:
BlackBulletIV wrote:Technically = isn't an operator in Lua, and it's actually not in the table of precedence in Programming in Lua. I found this out when I tried to do multiple assignment:
Yes, you're right. Assignment in Lua doesn't work like in C/C++ (in a sense that an assignment operation doesn't return a value).
By the way, you can 'sort of' do multiple assignments on the same line using: