cardWidth, cardHeight

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
tjo7777
Posts: 34
Joined: Fri May 02, 2014 9:16 pm

cardWidth, cardHeight

Post by tjo7777 » Thu May 08, 2014 5:58 pm

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.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: cardWidth, cardHeight

Post by jmburnod » Thu May 08, 2014 6:47 pm

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
https://alternatic.ch

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: cardWidth, cardHeight

Post by Klaus » Thu May 08, 2014 6:51 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10333
Joined: Wed May 06, 2009 2:28 pm

Re: cardWidth, cardHeight

Post by dunbarx » Thu May 08, 2014 7:05 pm

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10102
Joined: Fri Feb 19, 2010 10:17 am

Re: cardWidth, cardHeight

Post by richmond62 » Thu May 08, 2014 7:48 pm

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!

tjo7777
Posts: 34
Joined: Fri May 02, 2014 9:16 pm

Re: cardWidth, cardHeight

Post by tjo7777 » Fri May 09, 2014 3:58 am

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.

Post Reply