Array Problem -LC 7.0.1

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

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Array Problem -LC 7.0.1

Post by RossG » Mon Nov 09, 2015 2:26 am

My array doesn't appear to be set up the way it should.
(Tried to insert an image)

.........1
1........ 0
2......... 4

i.e the first element doesn't have an index number
but accepts data but isn't really the first element.
The first one is the second one with index 1.

(What about "Whose on next"!)

My problem or is it LC?

(Mod because my representation of the array didn't appear
in the post as in the preview)
Last edited by RossG on Mon Nov 09, 2015 12:21 pm, edited 2 times in total.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

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

Re: Array Problem -LC 7.0.1

Post by dunbarx » Mon Nov 09, 2015 3:44 am

Hi.

How did you make this array?

Craig Newman

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Array Problem -LC 7.0.1

Post by MaxV » Mon Nov 09, 2015 11:03 am

What is the result of:

Code: Select all

put the keys of my_array
??
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: Array Problem -LC 7.0.1

Post by RossG » Mon Nov 09, 2015 12:03 pm

I made the array with

repeat with i = 1 to 36
put 0 into theArray
end repeat.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: Array Problem -LC 7.0.1

Post by RossG » Mon Nov 09, 2015 1:40 pm

I had a thought that my prog. might have tried to put a number
into array[0] but have watched the array being set up in the
debugger and the ghost element appears after the 36 real ones.

So it's not being done by my prog.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Array Problem -LC 7.0.1

Post by FourthWorld » Mon Nov 09, 2015 4:16 pm

What does the code used to verify the array look like?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Array Problem -LC 7.0.1

Post by MaxV » Mon Nov 09, 2015 4:32 pm

Using this code:

Code: Select all

repeat with i = 1 to 36
   put 0 into theArray[i]
end repeat
put the keys of theArray into temp
sort numeric temp
put temp
I get

Code: Select all

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
No problem for me.
Moreover this code:

Code: Select all

repeat with i = 1 to 36
    put 0 into theArray[i]
end repeat
put the keys of theArray into temp
put the number of lines of temp
returns 36.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

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

Re: Array Problem -LC 7.0.1

Post by dunbarx » Mon Nov 09, 2015 5:04 pm

Hi.

All you have written, aside from the first post, is as it should be. Can you duplicate the result you got initially, with the missing first key?

As an aside, you have discovered, at least for me, that the sortDirection can be placed either before or after the container reference. Anyone else know this?

Craig

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Array Problem -LC 7.0.1

Post by FourthWorld » Mon Nov 09, 2015 5:07 pm

I wonder if the erroneous output might be the result of having two arguments for the combine command provided in the wrong order.

combine tVarA with tab and return

...will yield something that looks like the OP's example, but:

combine tVarA with return and tab

...will produce something more like what's expected.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: Array Problem -LC 7.0.1

Post by RossG » Mon Nov 09, 2015 5:55 pm

I've tried the same code in Rev 3.0 and it produces
the correct result.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Array Problem -LC 7.0.1

Post by FourthWorld » Mon Nov 09, 2015 7:32 pm

What does the code look like?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: Array Problem -LC 7.0.1

Post by RossG » Mon Nov 09, 2015 8:40 pm

ForthWorld

repeat with i = 1 to 36
put 0 into theArray
end repeat
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: Array Problem -LC 7.0.1

Post by RossG » Mon Nov 09, 2015 8:55 pm

Stranger and stranger.

I opened the one-button prog I did with Rev 3
to initialize the array in LC and it makes the
array correctly.

As for getting the index of the elements in the array
I think I'll settle for putting them into theArray[1] and
the other data into theArray[2].

Later:
I've set up the array successfully without putting 0 into
each element. One of those mysteries that may never
be solved.

Thank you all for your efforts.
Last edited by RossG on Mon Nov 09, 2015 9:03 pm, edited 1 time in total.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

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

Re: Array Problem -LC 7.0.1

Post by dunbarx » Mon Nov 09, 2015 8:57 pm

Hi.

This is what you posted before. This yields an array of 36 keys, each with a "0" as its associated element. Try:

Code: Select all

on mouseUp
   repeat with i = 1 to 36
         put 0 into theArray[i]
   end repeat
   
   combine theArray with return and comma
   sort theArray numeric
   put theArray into fld 1 --or whatever
end mouseUp
Works just fine. So are you saying that in a later version of LC, a similar handler loses the first key?

Craig

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: Array Problem -LC 7.0.1

Post by RossG » Mon Nov 09, 2015 9:19 pm

Craig

I'll not spend any time trying to solve this mystery.
Have to get on with my coding.

Later: I think my problem was caused by trying to delete
the array as it would be generated afresh on the next cycle.
I tried to put "" into each element.

Now, how do I "neutralize" the array?
delete array36
doesn't work.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

Post Reply