help with homework please thanks

For my homework I am doing it in corona and need to know if I make a square with new rectangle with corona then how do I get the area of the new square? [import]uid: 211931 topic_id: 36133 reply_id: 336133[/import]

Hi Bud,
Well, the area of a rectangle is just “base * height”. In specific, what do you need to do in Corona? The units of measurement are in pixels, so you can just get the area in pixels. What else do you need help with?

Sincerely,
Brent Sorrentino [import]uid: 200026 topic_id: 36133 reply_id: 143510[/import]

Thank you bryan I read the documents but I get an error when I try to do math on the base and height I tried local area = base * height but it says something about nil and then I changed it and it said something about up value so should it be nil or upvalue because it wont work still? [import]uid: 211931 topic_id: 36133 reply_id: 143529[/import]

Ah, I think what you mean then is this code:

local area = myRectangle.width \* myRectangle.height

Brent
[import]uid: 200026 topic_id: 36133 reply_id: 143534[/import]

Bud,

I’ve seen you post a lot of threads on a variety of problems, and that’s fine, the best way to learn is trial and error. You just need to learn what Corona is trying to tell you when you get an error so you know how to fix it. There’s no use moving on to the next problem without knowing what you’re doing wrong with the last one.
When Corona says something has a nil value, it means it doesn’t exist.

In this case, you have tried to do:

[lua]

local area = base * height

[/lua]

Corona responds by looking in memory for a variable or object called ‘base’. You haven’t defined anything called ‘base’ in your code, so it tells you it is nil. It can’t continue with the math operation and your program crashes.

Computers are not intelligent, they cannot reason that you meant the base of the rectangle you just created. It just goes ‘What do you mean, ‘base’? I’ve never heard of that before’. You have to be specific.

When you create your rectangle, you give it a name. You can see above Brent called his ‘myRectangle’.

Now myRectangle exists as a display object, it also has a number of properties that belong to it, such as X & Y position, alpha (1 = solid, 0.5 = part-transparent, 0 = invisible), rotation, height, width and more.

You can read these values like this:

[lua]

local rectHeight = myRectangle.height

local rectAlpha = myRectangle.alpha

[/lua]

And change these values like this:

[lua]
myRectangle.x = 300

myRectangle.rotation = 45
[/lua]
You can even set your own properties for an object:

[lua]

myRectangle.name = “Kevin”
myRectangle.age = 30

[/lua]

Now from this moment forward Corona understands that your rectangle has a ‘name’ and ‘age’ property, and if you tried to read these values you wouldn’t get an error. If you tried to do that before performing the above code, you’d get an error because Corona wouldn’t know what you were going on about. [import]uid: 93133 topic_id: 36133 reply_id: 143560[/import]

Thank you both of you that was really helpful I made it start working now [import]uid: 211931 topic_id: 36133 reply_id: 143678[/import]

Hi Bud,
Well, the area of a rectangle is just “base * height”. In specific, what do you need to do in Corona? The units of measurement are in pixels, so you can just get the area in pixels. What else do you need help with?

Sincerely,
Brent Sorrentino [import]uid: 200026 topic_id: 36133 reply_id: 143510[/import]

Thank you bryan I read the documents but I get an error when I try to do math on the base and height I tried local area = base * height but it says something about nil and then I changed it and it said something about up value so should it be nil or upvalue because it wont work still? [import]uid: 211931 topic_id: 36133 reply_id: 143529[/import]

Ah, I think what you mean then is this code:

local area = myRectangle.width \* myRectangle.height

Brent
[import]uid: 200026 topic_id: 36133 reply_id: 143534[/import]

Bud,

I’ve seen you post a lot of threads on a variety of problems, and that’s fine, the best way to learn is trial and error. You just need to learn what Corona is trying to tell you when you get an error so you know how to fix it. There’s no use moving on to the next problem without knowing what you’re doing wrong with the last one.
When Corona says something has a nil value, it means it doesn’t exist.

In this case, you have tried to do:

[lua]

local area = base * height

[/lua]

Corona responds by looking in memory for a variable or object called ‘base’. You haven’t defined anything called ‘base’ in your code, so it tells you it is nil. It can’t continue with the math operation and your program crashes.

Computers are not intelligent, they cannot reason that you meant the base of the rectangle you just created. It just goes ‘What do you mean, ‘base’? I’ve never heard of that before’. You have to be specific.

When you create your rectangle, you give it a name. You can see above Brent called his ‘myRectangle’.

Now myRectangle exists as a display object, it also has a number of properties that belong to it, such as X & Y position, alpha (1 = solid, 0.5 = part-transparent, 0 = invisible), rotation, height, width and more.

You can read these values like this:

[lua]

local rectHeight = myRectangle.height

local rectAlpha = myRectangle.alpha

[/lua]

And change these values like this:

[lua]
myRectangle.x = 300

myRectangle.rotation = 45
[/lua]
You can even set your own properties for an object:

[lua]

myRectangle.name = “Kevin”
myRectangle.age = 30

[/lua]

Now from this moment forward Corona understands that your rectangle has a ‘name’ and ‘age’ property, and if you tried to read these values you wouldn’t get an error. If you tried to do that before performing the above code, you’d get an error because Corona wouldn’t know what you were going on about. [import]uid: 93133 topic_id: 36133 reply_id: 143560[/import]

Thank you both of you that was really helpful I made it start working now [import]uid: 211931 topic_id: 36133 reply_id: 143678[/import]

Hi Bud,
Well, the area of a rectangle is just “base * height”. In specific, what do you need to do in Corona? The units of measurement are in pixels, so you can just get the area in pixels. What else do you need help with?

Sincerely,
Brent Sorrentino [import]uid: 200026 topic_id: 36133 reply_id: 143510[/import]

Thank you bryan I read the documents but I get an error when I try to do math on the base and height I tried local area = base * height but it says something about nil and then I changed it and it said something about up value so should it be nil or upvalue because it wont work still? [import]uid: 211931 topic_id: 36133 reply_id: 143529[/import]

Ah, I think what you mean then is this code:

local area = myRectangle.width \* myRectangle.height

Brent
[import]uid: 200026 topic_id: 36133 reply_id: 143534[/import]

Bud,

I’ve seen you post a lot of threads on a variety of problems, and that’s fine, the best way to learn is trial and error. You just need to learn what Corona is trying to tell you when you get an error so you know how to fix it. There’s no use moving on to the next problem without knowing what you’re doing wrong with the last one.
When Corona says something has a nil value, it means it doesn’t exist.

In this case, you have tried to do:

[lua]

local area = base * height

[/lua]

Corona responds by looking in memory for a variable or object called ‘base’. You haven’t defined anything called ‘base’ in your code, so it tells you it is nil. It can’t continue with the math operation and your program crashes.

Computers are not intelligent, they cannot reason that you meant the base of the rectangle you just created. It just goes ‘What do you mean, ‘base’? I’ve never heard of that before’. You have to be specific.

When you create your rectangle, you give it a name. You can see above Brent called his ‘myRectangle’.

Now myRectangle exists as a display object, it also has a number of properties that belong to it, such as X & Y position, alpha (1 = solid, 0.5 = part-transparent, 0 = invisible), rotation, height, width and more.

You can read these values like this:

[lua]

local rectHeight = myRectangle.height

local rectAlpha = myRectangle.alpha

[/lua]

And change these values like this:

[lua]
myRectangle.x = 300

myRectangle.rotation = 45
[/lua]
You can even set your own properties for an object:

[lua]

myRectangle.name = “Kevin”
myRectangle.age = 30

[/lua]

Now from this moment forward Corona understands that your rectangle has a ‘name’ and ‘age’ property, and if you tried to read these values you wouldn’t get an error. If you tried to do that before performing the above code, you’d get an error because Corona wouldn’t know what you were going on about. [import]uid: 93133 topic_id: 36133 reply_id: 143560[/import]

Thank you both of you that was really helpful I made it start working now [import]uid: 211931 topic_id: 36133 reply_id: 143678[/import]

Hi Bud,
Well, the area of a rectangle is just “base * height”. In specific, what do you need to do in Corona? The units of measurement are in pixels, so you can just get the area in pixels. What else do you need help with?

Sincerely,
Brent Sorrentino [import]uid: 200026 topic_id: 36133 reply_id: 143510[/import]

Thank you bryan I read the documents but I get an error when I try to do math on the base and height I tried local area = base * height but it says something about nil and then I changed it and it said something about up value so should it be nil or upvalue because it wont work still? [import]uid: 211931 topic_id: 36133 reply_id: 143529[/import]

Ah, I think what you mean then is this code:

local area = myRectangle.width \* myRectangle.height

Brent
[import]uid: 200026 topic_id: 36133 reply_id: 143534[/import]

Bud,

I’ve seen you post a lot of threads on a variety of problems, and that’s fine, the best way to learn is trial and error. You just need to learn what Corona is trying to tell you when you get an error so you know how to fix it. There’s no use moving on to the next problem without knowing what you’re doing wrong with the last one.
When Corona says something has a nil value, it means it doesn’t exist.

In this case, you have tried to do:

[lua]

local area = base * height

[/lua]

Corona responds by looking in memory for a variable or object called ‘base’. You haven’t defined anything called ‘base’ in your code, so it tells you it is nil. It can’t continue with the math operation and your program crashes.

Computers are not intelligent, they cannot reason that you meant the base of the rectangle you just created. It just goes ‘What do you mean, ‘base’? I’ve never heard of that before’. You have to be specific.

When you create your rectangle, you give it a name. You can see above Brent called his ‘myRectangle’.

Now myRectangle exists as a display object, it also has a number of properties that belong to it, such as X & Y position, alpha (1 = solid, 0.5 = part-transparent, 0 = invisible), rotation, height, width and more.

You can read these values like this:

[lua]

local rectHeight = myRectangle.height

local rectAlpha = myRectangle.alpha

[/lua]

And change these values like this:

[lua]
myRectangle.x = 300

myRectangle.rotation = 45
[/lua]
You can even set your own properties for an object:

[lua]

myRectangle.name = “Kevin”
myRectangle.age = 30

[/lua]

Now from this moment forward Corona understands that your rectangle has a ‘name’ and ‘age’ property, and if you tried to read these values you wouldn’t get an error. If you tried to do that before performing the above code, you’d get an error because Corona wouldn’t know what you were going on about. [import]uid: 93133 topic_id: 36133 reply_id: 143560[/import]