Some questions about arrays.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Some questions about arrays.
Hello, I'm new using RunRev, and I have some questions.
1) How do I create an array from 1 to 20 using a loop instruction, not manually? I need an array like this: [1,2,3,4,...,19,20]
2) How do I select a random value from the array?
3) How do I delete an element from the array?
4) Is there any variable that contains the array's lenght? Or do I need to create a function?
Sorry if these are basic questions for you, but I need help.
1) How do I create an array from 1 to 20 using a loop instruction, not manually? I need an array like this: [1,2,3,4,...,19,20]
2) How do I select a random value from the array?
3) How do I delete an element from the array?
4) Is there any variable that contains the array's lenght? Or do I need to create a function?
Sorry if these are basic questions for you, but I need help.
1. creating numerical keys:
2. Selecting random value:
3. Deleting a key:
4. No, there is no single line to get the length of all the values in an array (and in rev there normally is no need anyway). You could of course loop trough each line of the keys, and put the length of the contents:
Code: Select all
on mouseUp
repeat with x = 1 to 10
put "something" into theArray[x]
end repeat
put the keys of theArray
end mouseUp
Code: Select all
put theArray[any line of the keys of theArray]
Code: Select all
delete variable theArray["1"]
Code: Select all
put 0 into theSum
repeat for each key theKey of theArray
add the length of theArray[theKey] to theSum
end repeat
put theSum
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
For the array "length" are you talking about the number of keys (or indices)?
If you're used to arrays being of the numeric index type, such as
theArray[0], theArray[1], theArray[2] then you should be aware that in Rev you can use any value, numeric or text as the key (or index).
If you are used to having the length of theArray being returned as 3 in the 3 index example above, then you can get the "length" by returning "the number of lines in the keys of theArray"
If you're used to arrays being of the numeric index type, such as
theArray[0], theArray[1], theArray[2] then you should be aware that in Rev you can use any value, numeric or text as the key (or index).
If you are used to having the length of theArray being returned as 3 in the 3 index example above, then you can get the "length" by returning "the number of lines in the keys of theArray"
Thank you BvG and SparkOut, I'll try your solutions.
Thank you again.
Yes, that's it, the total number of keys (os values). RunRev script language is a bit different from the classic languages, and it's hard at the beginning.For the array "length" are you talking about the number of keys (or indices)?
Thank you again.
Sorry for the double posting.
I have this script in the main card:
I need to populate the "arrayA" with 20 elements (numbers from 1 to 20). Then, I wanna randomly choose 5 elements from arrayA and put'em into arrayB (and delete them from arrayA).
Also I need to show the arrayA into a text box...
What's wrong? So many things, I know... help!
I have this script in the main card:
Code: Select all
local state, elem, arrayA, arrayB
on preOpenCard
startProgram
end preOpenCard
on startProgram
put 0 into state
repeat with x = 1 to 20
put the value of x into arrayA[x]
end repeat
repeat with x = 1 to 5
put arrayA[any line of the keys of arrayA] into elem
put elem into arrayB[x]
delete variable arrayA[elem]
end repeat
end startProgram
Also I need to show the arrayA into a text box...
What's wrong? So many things, I know... help!
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
If you want to 'delete' a variable or an element in an array, you have to use the right key, not the value it contained - in Revolution, there are no pointer or reference variables.
Also, if you're using only numeric keys in your arrays, you can use the 'extents' property to figure out the dimensions.
HTH,
Jan Schenkel.
Code: Select all
local state, elem, arrayA, arrayB
on preOpenCard
startProgram
end preOpenCard
on startProgram
put 0 into state
repeat with x = 1 to 20
put the value of x into arrayA[x]
end repeat
repeat with x = 1 to 5
put any line of the keys of arrayA into elemKey
put arrayA[elemKey] into arrayB[x]
delete variable arrayA[elemKey]
end repeat
end startProgram
Code: Select all
on mouseUp
local tArray, tRow, tColumn
-- create a 10x5 matrix array
repeat with tRow = 1 to 10
repeat with tColumn = 1 to 5
put tRow,tColumn into tArray[tRow,tColumn]
end repeat
end repeat
answer the extents of tArray
end mouseUp
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com
Hi cogollo, i'm still slightly confused with arrays in Revolution (they're a bit different from my "array experience" when I used to use Lingo)...the more experienced guys'll help more, I'm sure.
To change an image transparency when clicked on is relatively straightforward:
and a nice effect you might want to try is to fade the image to the transparency required (or fade to nothing):
Hope that's useful for you.

To change an image transparency when clicked on is relatively straightforward:
Code: Select all
on mouseDown
set the blendlevel of me to 50
---for instance, where 0 is fully opaque and 100 is fully transparent---
end mouseDown
Code: Select all
on mouseDown
repeat with BlendOut = 0 to 100 step 2
set the blendlevel of me to BlendOut
wait 10 milliseconds
end repeat
end mouseDown

There is an article by Tom Healy on the Rev newsletter issue 57 http://www.runrev.com/newsletter/septem ... etter1.php which should also help you regarding arrays.