Livecode Tuturoal: A Simple Calculator

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
kespears
Posts: 27
Joined: Sat Aug 04, 2018 2:07 pm

Livecode Tuturoal: A Simple Calculator

Post by kespears » Fri Sep 06, 2019 2:28 pm

I'm working thru the http://www.live-code.net/livecode-tutor ... #section-7 and the Simple Calculator does not show the mouseUp results when I select a number or symbol. I went back through the code example and what I type many times (even backwards). Then I resorted to looking at the completed Simple Calculator http://live-code.net/examples and compared the code and inspector for each object. No difference. The only subtle difference I see is each of my label content is "grayed" out for some reason. Could that be the culprit? Below is the example for button "1".

Thanks
Keith
Attachments
Screen Shot 2019-09-06 at 8.27.28 AM.png

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Livecode Tuturoal: A Simple Calculator

Post by bogs » Fri Sep 06, 2019 3:02 pm

The Tutorial wrote:Edit the label properties of each button to "1, 2, 3, 4, 5, 6, 7, 8, 9, 0, +, -, *, /, ., =", and arrange them on screen as in this image:
I think the main problem is that you've set the name of the button to 1, not the label.

By default, an objects 'name' (the top box in your picture) will be the object name. If there is more than one object of the same type, the name will increment with a space and number, like this:

(new button) name = button
(2nd button) name = button 1
etc.

The label is grayed out because you typed 1 into the name. Using just a bare number or symbol for the name of an object is a bad idea.

The tutorial doesn't change the name of the button, and it is fine to leave (for this case) button, button 1, button 2, etc for the name.

Alternately, you can go back and rename each control. In the case of the buttons, you *could* name them something meaningful, like "keyOne", "keyTwo", "keyDivision", etc.
Image

kespears
Posts: 27
Joined: Sat Aug 04, 2018 2:07 pm

Re: Livecode Tuturoal: A Simple Calculator

Post by kespears » Fri Sep 06, 2019 3:12 pm

Bogs, That worked. Lesson learned. Thanks Keith

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Livecode Tuturoal: A Simple Calculator

Post by bogs » Fri Sep 06, 2019 3:14 pm

Happy to be of some help :D
Image

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Livecode Tuturoal: A Simple Calculator

Post by SparkOut » Fri Sep 06, 2019 5:20 pm

bogs wrote:
Fri Sep 06, 2019 3:02 pm
If there is more than one object of the same type, the name will increment with a space and number, like this:

(new button) name = button
(2nd button) name = button 1
etc.
:shock:
It will increment the name automatically?!
Attachments
The name the same.png

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Livecode Tuturoal: A Simple Calculator

Post by bogs » Fri Sep 06, 2019 7:17 pm

SparkOut wrote:
Fri Sep 06, 2019 5:20 pm
It will increment the name automatically?!
My bad, when I am using Lc, I am rarely past v6.5.2 (and usually much older). A bad habit I picked up was using 'Replicate' when I need more than one thing. When you use replicate, it certainly does name the copies automatically incremented --
replicateAutoIncrementedNaming.png
One little, two little, three little button names...
Unfortunately for me, I thought this was the default behavior no matter how you introduced extra objects, so good catch and thank you, SparkOut! :oops:
Of course, now I wonder why this isn't the default behavior, heh. I know they got rid of replicate :cry: but still...
Image

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Livecode Tuturoal: A Simple Calculator

Post by bogs » Fri Sep 06, 2019 7:39 pm

By the way, if you miss using the replicate palette, you can restore it in the IDE by copying it from the palettes folder to the plugins folder, where it apparently works just fine.

The path to it on 'nix is ~/.runrev/components/livecodecommunity-9.5.0.x86/Toolset/palettes/revreplicate.rev
revReplicate95_p2.png
Plug me in baby!!
revReplicate95.png
One little...
Image

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9655
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Livecode Tuturoal: A Simple Calculator

Post by dunbarx » Fri Sep 06, 2019 11:24 pm

Hi.

All good, I see.

But to lock this down, know that there are several ways to refer to a control. One VERY native way is that control's "layer" (1,2,3...). Another is its "name". There is an inherent conflict that will likely cause problems if a number is used as a name.

So if you have three fields, say, Livecode "knows" those fields as they are layered, that is, 1,2 and 3. If, in layer order, they are named "3,2,1", and you ask for "field 1", LC will assume you meant the field with layer 1, NOT the field named "1".

Now then, there is great advantage in referring to a suite of controls by an appended numerical value. Get in the habit of using names like "myField1, myField2..." or whatever, when you do that sort of thing. In the above naming example:

Code: Select all

repeat with y = 1 to 3
  put y * 10 into field "myField" & y
  end repeat
Try the above, and also some of your own experiments. This is fundamental stuff.

Craig

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Livecode Tuturoal: A Simple Calculator

Post by Klaus » Sat Sep 07, 2019 10:57 am

Code: Select all

...
 put y * 10 into field ("myField" & y)
...
8)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9655
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Livecode Tuturoal: A Simple Calculator

Post by dunbarx » Sat Sep 07, 2019 2:11 pm

Klaus makes a good point. Don't be sloppy.

Craig

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Livecode Tuturoal: A Simple Calculator

Post by bogs » Sat Sep 07, 2019 2:21 pm

Yes, but by all means be happy :D
Image

kespears
Posts: 27
Joined: Sat Aug 04, 2018 2:07 pm

Re: Livecode Tuturoal: A Simple Calculator

Post by kespears » Mon Sep 16, 2019 1:34 pm

Thanks all for the valuable information. Keith

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”