Arrays or Custom Properties or both

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

HJay
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 85
Joined: Sun Mar 04, 2012 12:16 pm

Re: Arrays or Custom Properties or both

Post by HJay » Sat Mar 31, 2012 11:08 pm

erm ButtonL and ButtonR still have no code assosiated with them?

The card script is in a different order...

...but the functionality of the stack still seems to be the same? :?

... sorry but am I missing something?

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Arrays or Custom Properties or both

Post by Dixie » Sat Mar 31, 2012 11:17 pm

It must be me that is 'doing the missing'...

As I understood you want to have one of your 'pairs', chosen at random, to appear in the labels of the buttons... then click the button whose number is represented in the button 'testNumber'... that's what is happening. If you choose the button whose label matches the number in the label of 'testNumber' then it tells you you have chosen correctly, otherwise tells you you have messed up...

script in each button..

Code: Select all

on mouseUp
   set the hilite of me to true
   if the label of me = the label of button "testNumber" then
      answer "You got it right!"
   else
      answer "Oops... wrong number"
   end if
   set the hilite of me to false
   setTheTest
end mouseUp
After clicking on a button, the test is reset... Have I got it completely wrong ?

be well

Dixie

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

Re: Arrays or Custom Properties or both

Post by dunbarx » Sun Apr 01, 2012 12:45 am

Oh fun. Glad you are engaged so. There is nothing wrong with attacking a problem in several ways, but I would stick with one at a time for now. If you want to use a custom property, go ahead. In this case it is overkill, but there is nothing wrong with that. Your questions:

Yes, they are all variables, and are temporary to the running handler. You can name these anything you want that is not reserved by the language. And yes, the LiveCode style is to place a small "t" in front for readability among the cognoscenti. Do that, absolutely. I just threw them together while driving home from work.

There are several kinds of variables, temporary, as these are, and more permanent types that have to be declared in the script. Later for those.

The variable "poosibles" contains all nine digits. Nothing random about it since it was populated explicitly with that string, which also contained the commas separating them.

Since the variable runs from "0" to "9", if you want to lose, say, "4", you need to lose the fifth item in that list. It is the "0" that makes this necessary. No other schema will do.

The "B" is just a letter so that I did not have to name either button with a number. NEVER do that. So since the buttons are named "B1" and "B2", I am able to address them with either the number "1" or "2" by creating the form "B" and concatenating either a "1" or "2". Button "B2" is addressed as "B" & "2". This is a powerful tool in the language, and you have to practice it.

Are you sure there is no handler at all in either button. Their scripts must not have even an empty "mouseUp" handler, in order for the message to be passed to the card.

I see Dixie is on this as well. Good. You are trying to cram a great deal of learining into a short time frame, based on a single project. That is not a bad way to start. Have patience, though, this jumpStart method will have snags for you since you are jumping in at a level quite above the novice. Write back...

Craig Newman

HJay
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 85
Joined: Sun Mar 04, 2012 12:16 pm

Re: Arrays or Custom Properties or both

Post by HJay » Sun Apr 01, 2012 9:55 am

Hi Dixie

I am unable to open the file this morning :?: I get the error message 'There was a porblem opening that stack: file is not a stack :?:

I am now under the impression that I thought I had opened it but hadn't really. Which is why it appeard to not look any differnt :?

There was a glass of red wine involved :oops:

so is there any chance you could post the stack you changed so I can try and open it.

Sorry about that.

HJay

HJay
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 85
Joined: Sun Mar 04, 2012 12:16 pm

Re: Arrays or Custom Properties or both

Post by HJay » Sun Apr 01, 2012 10:12 am

Hi Craig
If you want to use a custom property, go ahead. In this case it is overkill, but there is nothing wrong with that.
Originally thought I would do it this way as it seemed to be easier? Think I will stick to this for now as once I have got it doing as I want I can just change the custom property and maybe have words to match etc. (can you put pictures into a custom property? One for the future)

Yes, they are all variables, and are temporary to the running handler. You can name these anything you want that is not reserved by the language. And yes, the LiveCode style is to place a small "t" in front for readability among the cognoscenti. Do that, absolutely. I just threw them together while driving home from work.
Wow :!:

Since the variable runs from "0" to "9", if you want to lose, say, "4", you need to lose the fifth item in that list. It is the "0" that makes this necessary. No other schema will do.
doh! I knew it would be something simple :oops: So if I had put the numbers in as "1,2,3,4,5,6,7,8,9,0" it wouldn't need the + 1 ?
The "B" is just a letter so that I did not have to name either button with a number. NEVER do that. So since the buttons are named "B1" and "B2", I am able to address them with either the number "1" or "2" by creating the form "B" and concatenating either a "1" or "2". Button "B2" is addressed as "B" & "2". This is a powerful tool in the language, and you have to practice it.
Ok think I will just refer to the button name for now, will have a go at that at a later date.
Are you sure there is no handler at all in either button. Their scripts must not have even an empty "mouseUp" handler, in order for the message to be passed to the card.
There was empty mouseups on both ButtonL and ButtonR have now deleted both but it is still not working when I click either ButtonL or ButtonR
You are trying to cram a great deal of learining into a short time frame, based on a single project. That is not a bad way to start. Have patience, though, this jumpStart method will have snags for you since you are jumping in at a level quite above the novice.
Think I might make myself some flash cards of basic things I need to learn, might need some help in working out what I need to learn but I will post that with a seperate topic

Many many thanks

HJay

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Arrays or Custom Properties or both

Post by Dixie » Sun Apr 01, 2012 10:19 am

Hi... Sorry, the stack was created using 5.5. I have now saved it again in legacy format, so if you are not running liveCode 5.5 you should now be able to open it...

be well

Dixie
Attachments
ClickingNumbers 2.livecode.zip
(1.81 KiB) Downloaded 200 times

HJay
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 85
Joined: Sun Mar 04, 2012 12:16 pm

Re: Arrays or Custom Properties or both

Post by HJay » Sun Apr 01, 2012 10:21 am

Hi Craig
Are you sure there is no handler at all in either button. Their scripts must not have even an empty "mouseUp" handler, in order for the message to be passed to the card.

There was empty mouseups on both ButtonL and ButtonR have now deleted both but it is still not working when I click either ButtonL or ButtonR
You were right, you were right, you were right! I just hadn't click the save button.

so now it works on the buttons as well as everywhere else. How do I stop it working everywhere else?

Thanks in advance

HJay

HJay
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 85
Joined: Sun Mar 04, 2012 12:16 pm

Re: Arrays or Custom Properties or both

Post by HJay » Sun Apr 01, 2012 11:45 am

Thanks Dixie

That is exactly what I want :D

Now all I have to do is work out how you did it :?

HJay

HJay
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 85
Joined: Sun Mar 04, 2012 12:16 pm

Re: Arrays or Custom Properties or both

Post by HJay » Sun Apr 01, 2012 11:48 am

But I would if possible like to know why this didn't work?

Code: Select all

on mouseup
   Set itemDel to tab
   put the cNumberPairs of this card into thePairs
   sort lines of thePairs by random(the number of lines of thePairs)
   Set the label of button "ButtonL" to item 1 of line 1 of  thePairs
   Set the label of button "ButtonR" to item 2 of line 1 of thePairs
   put item 1 of line 1 of thePairs into thePairsL
   put item 2 of line 1 of thePairs into thePairsR
   put any item of "1,2" into thePairsLorR 
   if thePairsLorR = 1 then set the label of button "testNumber" to  thePairsL 
   if thePairsLorR = 2 then set the label of button "testNumber" to  thePairsR
end mouseup
Many thanks

HJay

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

Re: Arrays or Custom Properties or both

Post by dunbarx » Sun Apr 01, 2012 3:57 pm

Think about this. If you had "1,2,3,4,5,6,7,8,9,0", you could easily say that to delete the fourth item you could reference it with a "4", and the "+ 1" thing is not required. But then how would you delete the last item, "0"? You cannot say "delete item 0", and you don't want to say "delete item 10", since now the numbers do not map as single digits: you would not be able to simply "delete item currentDigit..."

So it is a workaround to keep one digit in hand, and reference a string that has ten items in it, one of which has a cardinality of two digits.

Craig Newman

HJay
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 85
Joined: Sun Mar 04, 2012 12:16 pm

Re: Arrays or Custom Properties or both

Post by HJay » Sun Apr 01, 2012 5:47 pm

Hi Craig

So it is the 0 that causes all the problems if I had wanted to use "1,2,3,4,5,6,7,8,9" with no zero then the "+1" would not have been needed, I think?

I also understtand the "B" "1" and "2" a bit more now as well now I have spent some more time in the variable watcher :)

HJay :D

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

Re: Arrays or Custom Properties or both

Post by dunbarx » Sun Apr 01, 2012 11:50 pm

Hjay.
So it is the 0 that causes all the problems if I had wanted to use "1,2,3,4,5,6,7,8,9" with no zero then the "+1" would not have been needed, I think?
Exactly. Again, you had ten items and my scheme used a simple, single digit method of identifying any one of them. It is just a way to do it, there are a million others. Note that if you had more than ten items, a single digit would no longer have been enough. Right? We would need a different scheme.
I also understtand the "B" "1" and "2" a bit more now as well now I have spent some more time in the variable watcher
The idea of "B" & 1 simply allows you to access one or the other of two buttons, named "B1" and "B2 with a number. It is nothing more than that, a scheme. You have to be famiiar with LC's ability to concatenate strings, and how this ability can be used to tremendous advantage. This will lead you to the concept of "chunking" developed way back when with Hypercard, and is the most fun and powerful text processing toolset you could ask for.

How are you coming with the custom property thing? I love these, as they are permanent, accessable, and convenient. But they are more useful as a lookup table, especially in your case, I think, and it seems to me that a small computational widget is more appropriate. But that is entirely up to you, and practice in using custom properties has value in and of itself.

Keep going. Keep asking...

Craig Newman

HJay
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 85
Joined: Sun Mar 04, 2012 12:16 pm

Re: Arrays or Custom Properties or both

Post by HJay » Mon Apr 02, 2012 9:55 am

The custom property thing is coming on quite nicely. I like it because you can just look at it and also but I haven't tried it yet, I guess I can put another series of data in the custom property and I will get different things to match without changing any of the code?

I understand I will need to get my head round the computational widget (which I am presuming is using code to do maths etc. rather than the things you find in the bottom of beer cans :D). Hopefully when the book arrives it will help me with this.

Thanks

HJay

HJay
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 85
Joined: Sun Mar 04, 2012 12:16 pm

Re: Arrays or Custom Properties or both

Post by HJay » Mon Apr 02, 2012 4:15 pm

Hi Dixie

Have been trying to work out what each bit does, some I think I know, some I have guessed and some I have no idea. Can you tell me what I got right and what I got wrong please :)

Code: Select all

on openCard
   lock screen
   setTheTest
end openCard
This stop the user seeing something but what is it stopping the user seeing?

Code: Select all

on closeCard
   repeat with count = 1 to 3
      set the label of button count to space
   end repeat
end closeCard
Where is button count and why do we want to set the label to space?

Code: Select all

on setTheTest
   lock screen
   set the label of button "buttonL" to space
   set the label of button "buttonR" to space
Again I don’t know why these buttons are being labelled space? But I guess this is what the lock screen command is not showing?

Code: Select all

 set itemDel to tab
   put the cNumberPairs of this card into thePairs
   sort lines of thePairs by random(the number of lines of thePairs)
I think this prepares the custom property and then assigns it to a variable
then randomly sorts them – does it mean that each and every line of thePairs is used in a random order or are they just randomly accessed so the same line could appear twice or more in a row?

Code: Select all

 put random(2) into whichNumber
   set the label of button "testNumber" to item whichNumber of line 1 of thePairs
This decides if the test number is going to appear on the left or right an puts the test number at the top

Code: Select all

  if whichNumber = 1 then 
      set the label of button "ButtonR" to item 1 of line 1 of thePairs
      set the label of button "ButtonL" to item 2 of line 1 of thePairs
   else
      set the label of button "ButtonL" to item 2 of line 1 of thePairs
      set the label of button "ButtonR" to item 1 of line 1 of thePairs
   end if
This bit actually puts the numbers on the left or right button

end setTheTest

How did I do with working out what you had done?

HJay

p.s have just purchased 5.5

Post Reply