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

Arrays or Custom Properties or both

Post by HJay » Thu Mar 29, 2012 9:20 pm

Right, here goes, bear with me...

I have a card, with two buttons on it ButtonL and ButtonR, and a label at the top called MatchLabel which will contain a single digit no. I want that label to match the number on either ButtonL or ButtonR

I have a custom property set up on the card called cNumberPairs which contains:-

1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
0 1
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1

Etc. and so on, of all the possible number combinations excluding matching pairs.

What I want to happen is, the single digit number will be displayed at the top (I will have a start button) and then when the matching ButtonL or ButtonR are clicked on the label at the top changes to another random single digit number as does ButtonL and ButtonR

I have done some reading around arrays and have managed to get the button labels to change to the first line of the array when the array is sitting on the card in a field below but I don’t want the data to be seen so I have moved it to a custom property on the card.

I am unable to get the data onto the button labels now and have got all confused with arrays and custom properties :?: are they things you use either one or the other of or do you use them together.

I hope that all made sense :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 » Thu Mar 29, 2012 9:37 pm

I tried reading this several times, and still do not quite get it.

The good news is that I see enough of what you are trying to do to know that the answer will be very simple. And I think a custom property will do nicely.

So you press a start button, and then what? Does a random digit load into the label field? If so, do random digits then modify the button labels? Does one or the other of those button labels load with the field digit? Is the idea to see that one or the other buttons shows the same digit, and one should then push that button?

Write back. This will be fun.

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 » Thu Mar 29, 2012 10:14 pm

Sorry I did try and make it less confuisng :oops:

What should initially be seen should be a single digit number between 0 and 9 in the label field. Also at the same time you would see two buttons a left and a right one, one of which contains a matching number (they cannot both match). When either of the left or right buttons are clicked the field label button should change to another random single digit number between 0 and 9 with another set of numbers on the left and right button (only one of which matches). I set the cNumberMatch custom property to contain :-

1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
0 1
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
0 2
1 2
3 2
4 2
5 2
6 2
7 2
8 2
9 2
0 3
1 3
2 3
4 3
5 3
6 3
7 3
8 3
9 3
0 4
1 4
2 4
3 4
5 4
6 4
7 4
8 4
9 4
0 5
1 5
2 5
3 5
4 5
6 5
7 5
8 5
9 5
0 6
1 6
2 6
3 6
4 6
5 6
7 6
8 6
9 6
0 7
1 7
2 7
3 7
4 7
5 7
6 7
8 7
9 7
0 8
1 8
2 8
3 8
4 8
5 8
6 8
7 8
9 8
0 9
1 9
2 9
3 9
4 9
5 9
6 9
7 9
8 9

Which is every single digit combination without having duplicate numbers, I had hoped to get the pairs to appear in a random order.

I did get the feeling this should be simple but I am only just learning the language at the moment.

I work with learning disabled pupils, this is a technique called matching to sample, they are presented with a number and they have to matching from two possible numbers. Is there also a way of recording how many they get right?

Many thanks :D

Does that make more sense?

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 » Fri Mar 30, 2012 12:12 am

Yes. I get it now. Seems like a worthy project.

So in your "start" button, does this make sense"?

Code: Select all

on mouseUp
   put "0,1,2,3,4,5,6,7,8,9" into possibles 
   put any item of possibles into currentDigit
   delete item currentDigit + 1 of possibles  -- why + 1?
   set the label of btn  "testNumber" to currentDigit
    put any item of "1,2" into currentButton
   if currentButton = 1 then put 2 into otherButton else put 1 into otherButton
   set the label of btn ("B" & currentButton ) to currentDigit
   set the label of btn ("B" & otherButton ) to  any item of possibles
end mouseUp
This assumes you have four buttons. One named "start", one named "B1", one named "B2", and one named "testNumber". I did not use a label field. I wonder why?

Your payment for this is to read each line and understand it. There are a million ways to do the cutesy number gathering. I used a brute force method, but it is easier to read. Further payment would be to make this your own with new functionality or reworking what is already here, like using a custom property in some way. This does not. Write back...

Craig Newman

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 » Fri Mar 30, 2012 12:23 am

Hi...

To get your 'pairs' to appear in a random order... try something like

Code: Select all

   put the cNumberPairs of this stack into thePairs
   sort lines of thePairs by random(the number of lines of thePairs)
   put thePairs

Also, have a look at 'random' in the dictionary to help you decide which number of a pair you will display in your 'label' field...

I'll leave the rest to Craig :D

be well

Dixie

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 » Fri Mar 30, 2012 9:48 pm

Payment will be recieved in full, you just may have to give me a bit of time :D

Thanks

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 3:25 pm

Hi Craig

Am I correct in presuming possibles, currentDigit , currentButton and otherButton are variables?

If so is there any reason why they are not called tPossibles, tCurrentDigit, tCurrentButton and tOtherButton? So far I have only come across variable with t in front of them. Is this significant?

Oh are variables and temporary variables different? Eek :o

This is what I think is happening in the code. Am I correct?

put "0,1,2,3,4,5,6,7,8,9" into possibles --This randomly assigns 0-9 to possibles

put any item of possibles into currentDigit -- This randomly assigns any digit in possibles to currentDigit

delete item currentDigit + 1 of possibles -- why + 1? --hmm I know what it is doing but am not sure why it is doing it. It stops the same digit appearing on B1 and B2. When I make it +2 it is possible to have the same number on B1 and B2 and when I take +1 out it is also possible to have the same number on B1 and B2. Am confused if currentDigit is the one that is to be matched then why is it currentDigit +1 rather than currentDigit that gets deleted from possibles? I have even had a look in the variable watcher. I guess there is a really simple answer to the question but it is eluding me at the moment

set the label of btn "testNumber" to currentDigit -- This sets the button “testNumber” label to currentDigit

put any item of "1,2" into currentButton
if currentButton = 1 then put 2 into otherButton else put 1 into otherButton
-- These two lines randomly assign B1 or B2 to be the correct answer

set the label of btn ("B" & currentButton ) to currentDigit
set the label of btn ("B" & otherButton ) to any item of possibles
-- These two lines sets the labels of B1 and B2 but how come they are referred to as B rather than B1 or B2? Does referring to them as B mean you refer to both or either? What does the & do it’s not in the dictionary :?

I did not use a label field. I wonder why? I am afraid I have no idea?


Hi Craig and Dixie

I have taken bits of both of your code and have come up with this:-

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
The first part sort of works where I get data from cNumberPairs to show in ButtonL and ButtonR, I say sort of works because it doesn’t work if I click either of ButtonL or ButtonR but it does work if I click anywhere else. I thought that if there was no code on the button then the message would be passed up to the card?

The next bit to not work is the bit where I try to get testNumber to randomly match ButtonL or ButtonR

Have learned quite a bit I think but further help would be appreciated :)

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 8:01 pm

Hi

It seems to be something to do with

Code: Select all

put any item of "1,2" into thePairsLorR
in the variable watcher it puts 1,2

but

Code: Select all

put any item of "1,2" into currentButton
in the variable watcher this puts either 1 or 2

the only difference between the two lines of code, that I can see, is one code is on the card and the other is on a button?

any ideas?

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 » Sat Mar 31, 2012 8:55 pm

Can you post your stack... as I am still confused about what you are trying to do..

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 9:15 pm

Only if you tell me how to :?

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 9:21 pm

When you 'click' .. 'Post Reply' to answer this posting you will see a tab under the 'Save Draft', 'Preview' and "Submit' buttons that is titled 'Upload Attachment'.
Clicking on 'the 'Upload Attachment' tab will allow you to browse to your stack to select it... (zip your stack to post it) once selected you can then click on the 'Add the file' button to attach it to your post...

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 9:47 pm

erm I can't find the file to zip it up, I have the file path 'C:\Program Files\RunRev\LivecCode 5.0.2\Matching to Sample.Livecode' but when I go looking for it it is not there. I have the computer set to show hidden files?

I even changed the file name to be able to search for it, it does not show up?

What am I doing wrong? :oops:

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 10:02 pm

Hi... :D I don't know what you are doing wrong
You could email it to john@ihouse.on-rev.com

be well

Dixie

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 10:10 pm

Good grief...

... have managed to zip it up now had to send it to document before I had to send it to compressed file...

...have never had so much trouble compressing a file!

right where was I

I do hope that worked. Fingers crossed :roll:
Attachments
Matching to Sample 2.zip
(1.38 KiB) Downloaded 227 times

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 10:54 pm

I have changed your scripts a little... look at the scripts of buttons left and right and the card script...

I hope it helps

be well

Dixie
Attachments
clickingNumbers.livecode.zip
(1.8 KiB) Downloaded 200 times

Post Reply