Can we have arrays


#1

Any chance of implementing arrays in Hopscotch?


#2

It would be great to be able to do

For I from 1 to 5
Set invisibility of variable V(i) to 100


#3

if value is less than 5 and value is more than 1 do
set invisibility to 100


#4

Hopscotch doesn't currently have them but @ThinBuffalo made a workaround using clones:

@NMhopscotch


#5

You can replicate this code pretty easily in Hopscotch. :)

Repeat 5:
    Set invisibility to (self.invisibility + 20)

#6

Is that what he wants? I thought his code was looping through 5 variables in an array and setting their invisibility all to 100.


#7

Nope, s/he's setting an individual object's invisibility.

I'd assume "V" is an initialized object in the programming language s/he's using.


#9

Oh jeez, are you back?
Stop, thanks.


#10

It seems that they are replying by email and this is something that is auto added onto the end of their replies


#11

Wait, don't flag his post. It is not a spam bot, it is @NMhopscotch, he has a default signature for his email, hence the name and address thingy.


Sorry for the confusion, @Neville_Moray.


#12

Shoot .
I'm so sorry, @Neville_Moray


#13

@NMhopscotch
You can do what you want in Hopscotch but it's a bit of a paradigm shift from what you're used to.

The only "array" in Hopscotch is essentially equivalent to

Dim myName(n) as Object

(meaning you can not directly have an array of values)

except the syntax of addres.sing the specific array index with (n) doesn't exist. Think about it as if the index was just a property in the object class definition.

Your array of objects will be "clones" in the Hopsotch vernacular. Add an Object Variables of "Index" and "Value" for the clones to use. And for the sake of discussion, create 5 clones in your project (4 plus the original). When the clones are created, a unique Index property is assigned for each clone (0-4).

Now consider how clones work. Any event triggers for all clones. So properties of the clones (i.e. the entire array) can easily be set in response to an event without code that loops through all of the array elements. For example,

When iPad is pressed (or some other event)
    Set (self) Value to (self) Index ^ 2
    Set Text to (Value)
    Set Position to x (500) y (100 + 100 * (self) Index)

This will make the object display the value and give each a different position. Self object reference allows you to change the different objects without having to addres.s them explicitly.

If you want only a specific index to respond to an event, you simply add a conditional statement to check the Index property (since the event triggers for all clones)

If you want to addres.s a specific object (or rather array element) by Index from an external subroutine (i.e. a different object's event), you can do that too but it's a little more difficult. You just have to use additional variables to pass the intended array index and values back & forth. You also have to use a variable to trigger an event in the "array of objects" to set and read the desired value.

Granted it's convoluted, but it works. If any of that doesn't make sense I could make an example to show you.


#14

Many thanks, ThinBuffalo , for a clear and thorough treatment of my problem. I will try to use this in the next few days, and let you know how I get on. Do you think Hopscotch will ever implement arrays with index?
Stryx

Neville Moray
Moray2@wanadoo.fr
+33 (0)493-36-07-58
www.morayart.com
17 Avenue des Genets,
06520 Magagnosc, France

My book "Science, Cells and Souls: An Introduction to Human Nature" is published by Authorhouse and is available on Amazon and Kindle. An Amazon review kindly says,"This is one of the most important cognitive science books published in the past decade. The author is a scholar who played an historic role in the cognitive revolution."


#15

It would be great to have an example if it is not too much trouble.
Stryx

Neville Moray
Moray2@wanadoo.fr
+33 (0)493-36-07-58
www.morayart.com
17 Avenue des Genets,
06520 Magagnosc, France

My book "Science, Cells and Souls: An Introduction to Human Nature" is published by Authorhouse and is available on Amazon and Kindle. An Amazon review kindly says,"This is one of the most important cognitive science books published in the past decade. The author is a scholar who played an historic role in the cognitive revolution."


#17

Example project, as promised


#18

Thanks.

Stryx

Neville Moray
Moray2@wanadoo.fr
+33 (0)493-36-07-58
www.morayart.com
17 Avenue des Genets,
06520 Magagnosc, France

My book "Science, Cells and Souls: An Introduction to Human Nature" is published by Authorhouse and is available on Amazon and Kindle. An Amazon review kindly says,"This is one of the most important cognitive science books published in the past decade. The author is a scholar who played an historic role in the cognitive revolution."


#19

Thanks, this is very helpful. You ask what I want an array for. If you open my STOCK MARKET Hopscotch app, you will see three dice at the bottom of the page. If you tap the first die, or the window associated with it, the name of a stock appears in that window. If you tap the second die or window you get a change in the stock value between -10 and +10. Higher up there is a grid of which the middle column should contain the cumulated value of the stock, i.e. the result of successively adding the successive values of the second die. The index of the array will be the name of the stock. The value of the indexed cell will be the cumulative values of successive rolls of the second die.

Clearly your solution will work, although it will end up as a very large and complex program.

Thanks for your help and interest.
Stryx

Neville Moray
Moray2@wanadoo.fr
+33 (0)493-36-07-58
www.morayart.com
17 Avenue des Genets,
06520 Magagnosc, France

My book "Science, Cells and Souls: An Introduction to Human Nature" is published by Authorhouse and is available on Amazon and Kindle. An Amazon review kindly says,"This is one of the most important cognitive science books published in the past decade. The author is a scholar who played an historic role in the cognitive revolution."


#21

I don't understand why people choose to spam or have bots spam on little random forums like this.

I'm really curious how that works. Does anyone know?


#22

@codingCupcake123 ^^^^^^^


#23

@NMhopscotch
The example I made only appears complicated because of the GUI & keypad I wrapped around the core ideas. The basic code needed to use clones as an array of values is very simple.

I would be happy to copy images of & explain the specific, minimum required portions of the code if that would be helpful?