Page 1 of 1

cardWidth, cardHeight

Posted: Thu May 08, 2014 5:58 pm
by tjo7777
I recently discovered cardWidth and cardHeight when learning how to maintain the position of controls when resizing the card.

Now I want to use cardWidth and cardHeight to position an image at a random position on the card, even when the card has been resized.
Say my object is 100x100 I wanted to do something like this:

Code: Select all

put cardWidth-100 into cwidth
put cardHeight-100 into cheight
put random(cwidth) into rwidth
put random(cheight) into rheight
set the topleft of image "image" to rwidth, rheight
when I try to run this code I get the error:

button "START":execution error at line 25 (Operators-:error in left operand), char11

Line 25 mentioned in the error is actually line 1 of the code snippet I posted.

The only thing I can think of is when I use cardWidth and cardHeight for resizing I first have a line like:

Code: Select all

on resizeStack cardWidth, cardHeight 
Do I need to add a similar line of code to tell LiveCode to "get" the cardWidth and cardHeight?

Thanks for any ideas or suggestions,

TJ.

Re: cardWidth, cardHeight

Posted: Thu May 08, 2014 6:47 pm
by jmburnod
Hi Tj,
I recently discovered cardWidth and cardHeight
Where ? :shock:
As far I know "cardWidth" doesn't exist. One card have the width and height of the stack
Try this

Code: Select all

put the width of this stack-100 into cwidth
put the height of this stack-100 into cheight
Kind regards
Jean-Marc

Re: cardWidth, cardHeight

Posted: Thu May 08, 2014 6:51 pm
by Klaus
Hi TJ,

the example resizestack handler in the docs just has some arbitrary, yet meaningful names for the parameters it comes with!
Could also be:
on resizeStack James, Harold, Bill, Carl
:D

cardHeight and cardWidth are not valid/built-in Livecode constants or properties!
So you need to "roll" your own:
...
put the width of this cd into cardWidth
put the height of this cd into cardHeight
put cardWidth-100 into cwidth
...

Best

Klaus

Re: cardWidth, cardHeight

Posted: Thu May 08, 2014 7:05 pm
by dunbarx
All.

This happens often. A new user will see these sorts of things in a lesson, or even in a handler that someone has written, and consider them native. As Klaus said, "roll your own", but somebody else already did. The new user assumes these are part of the language.

It is an important lesson in its own right that the newbie sees how this is done, that in a sense, those new words are now, indeed part of the language, but that they were engineered outside that language.

So TJ, where did you see these "cardWidth, etc" properties?

Craig Newman

Re: cardWidth, cardHeight

Posted: Thu May 08, 2014 7:48 pm
by richmond62
Yes; this can be a problem.
suspicion.png
I recently made a prototype code block stack: http://andregarzia.on-rev.com/richmond/GR.zip

with a whole lot of groups with scripts of this sort

on ACTION
do something
end ACTION

and a kid I sent the stack to came back within half-an-hour asking my why "action" wasn't in the LC Dictionary.

So, maybe, we should be kind and label our "personal funnies" as such to avoid confusion.
quality.gif
ALWAYS read the label!

Re: cardWidth, cardHeight

Posted: Fri May 09, 2014 3:58 am
by tjo7777
Thanks for the help everyone. Yes, Craig I did see this in a tutorial on resizing cards found here:
http://lessons.runrev.com/s/lessons/m/4 ... is-resized

In the tutorial cardWidth/cardHeight was just used with the on resizeStack, I was thinking these were native, but obviously it's pretty easy to get the effect I am looking for by "rolling my own" and using something like:

Code: Select all

put the width of this card into cardWidth
Thanks again everyone for all the help. Very much appreciated.

TJ.