Page 2 of 2
Re: Arrays or Custom Properties or both
Posted: Sat Mar 31, 2012 11:08 pm
by HJay
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?
Re: Arrays or Custom Properties or both
Posted: Sat Mar 31, 2012 11:17 pm
by Dixie
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
Re: Arrays or Custom Properties or both
Posted: Sun Apr 01, 2012 12:45 am
by dunbarx
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
Re: Arrays or Custom Properties or both
Posted: Sun Apr 01, 2012 9:55 am
by HJay
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
so is there any chance you could post the stack you changed so I can try and open it.
Sorry about that.
HJay
Re: Arrays or Custom Properties or both
Posted: Sun Apr 01, 2012 10:12 am
by HJay
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

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
Re: Arrays or Custom Properties or both
Posted: Sun Apr 01, 2012 10:19 am
by Dixie
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
Re: Arrays or Custom Properties or both
Posted: Sun Apr 01, 2012 10:21 am
by HJay
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
Re: Arrays or Custom Properties or both
Posted: Sun Apr 01, 2012 11:45 am
by HJay
Thanks Dixie
That is exactly what I want
Now all I have to do is work out how you did it
HJay
Re: Arrays or Custom Properties or both
Posted: Sun Apr 01, 2012 11:48 am
by HJay
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
Re: Arrays or Custom Properties or both
Posted: Sun Apr 01, 2012 3:57 pm
by dunbarx
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
Re: Arrays or Custom Properties or both
Posted: Sun Apr 01, 2012 5:47 pm
by HJay
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

Re: Arrays or Custom Properties or both
Posted: Sun Apr 01, 2012 11:50 pm
by dunbarx
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
Re: Arrays or Custom Properties or both
Posted: Mon Apr 02, 2012 9:55 am
by HJay
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

). Hopefully when the book arrives it will help me with this.
Thanks
HJay
Re: Arrays or Custom Properties or both
Posted: Mon Apr 02, 2012 4:15 pm
by HJay
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