2017년 5월 19일 금요일

What is a list ?


From the documentation, a list is a 1 dimensional matrix of space separated items enclosed by brackets.

I've created such a list from a returned Json string, stripping off everything I don't need, and AI tells me it's not a list.
So what is a list then.


--
I've created such a list from a returned Json string,
to convert a JSON string into a list, use the JsonTextDecode method from the web component



any JsonTextDecode(text jsonText)
Decodes the given JSON encoded value to produce a corresponding AppInventor value. A JSON list [x, y, z] decodes to a list (x y z), A JSON object with name A and value B, (denoted as A:B enclosed in curly braces) decodes to a list ((A B)), that is, a list containing the two-element list (A B).

--
A list is a chain of items in memory, each pointing to the next item in the list.
It is not an array, which gets pre-allocated memory to put the items in adjacent locations in memory.

See attached for a dangerous but simple list that will bust the stack if you try to generate a text version of it.

Ouroboros is the Greek legendary snake that survives by eating itself, tail first.



--

Moving the Character


Im making my first project in the app inventor. My game is a snakes and ladders game, I'm having an issue in animation My issue is that how can I make a charter move from a block to another without teleporting the character. Example: I was on block 20 and the dice appeared to be 5 and I teleported to the block 25. My question is how can I make the character move to the other blocks(21,22,23,24) with 1 second interval Then reach 25 using animation ..... I tried using clock function but not figured it out yet .... any idea ?

--
You need to post your blocks and how you define the location of each block so we can figure out how to help you.

--
You need to keep a list of the moves you want to make, in order,
((piece, from, to)
(piece, from, to)
(piece, from, to)
...)

And have the clock timer routine service it one move per cycle,
removing from the list as it goes.

Look in the FAQ for How to Work With Lists:

--

is the spinner a list?


do you add items directly into the spinner using the add items to list block and spinner elements block as the list ?
or do you have to create a global variable as a list , then every add the item to the global variable list , then set the spinner element to the global variable list then save the global variable list on the tiny db, then when screen initializes, initialize the global variable list to the value from tiny db, and set the spinner elements to the global variable list?(the item is a tag and is added when a user saves something ) 
thanks! :) 

--
Nope... you can only add items as elements.  So, you would have to make a CSV list and use that to add the items.  In addiiton, you can't do one at a time, but instead have to set the entire list of elements at once...

--
so I have to set the spinner elements to a list, and add the items to that list then update the elements,
thank you! :)

--
Not necessarily Jen...

You could also do Set Spinner.Elements to Dog,Cat,Whale,Fox,Teddy Bear,Alligator,Snake

Just build a CSV list like that.  You could also build a regular list and then set the elements to that.

--
yes i understand, im just using a global variable list because my items for the spinner are responses from the notifier which are tags which are stored in the tiny db.
thanks for your help.

--

search for snake


Keep the component blocks for the ImageSprites in a list from 1 to the number of segments in the snake. item 1 is the tip of the tail, item n is the head.
Hi all,. I'm making a Snake game with App Inventor 2 but I don't know how to grow the snake, everything workes except how to grow the snake.
Not necessarily Jen... You could also do Set Spinner.Elements to Dog,Cat,Whale, Fox,Teddy Bear,Alligator,Snake Just build a CSV list like that.
Hello,. Im making my first project in the app inventor. My game is a snakes and ladders game, I'm having an issue in animation My issue is that how ...
See attached for a dangerous but simple list that will bust the stack if you try to generate a text version of it. Ouroboros is the Greek legendary snake ...


Is making multiple instances of a sprite possible?


I found one topic that said no so I want to confirm this as this is a fairly basic thing you should be able to do and I really hope I don't have to learn how to use android studio although I do know java. I'm making a game where if you collide with a certain object, a duplicate of that object will appear elsewhere on the screen. Is there any way to duplicate them? or do you actually have to make a whole bunch of invisible/inactive sprites on the canvas to have this same effect? 

--
You cannot instantiate Sprites at runtime, so as you mentioned, you will have to have a bunch of them hidden if you want to do something like that.

--
I'm making a game where if you collide with a certain object, a duplicate of that object will appear elsewhere on the screen.
If your first instance disappears when the copy appears it is a simple process of moving the original sprite to the new location.
If the sprite disappears during the move and there is a delay between first position and second postion, then use a clock timer and the ImageSprite Visible property to hide then reveal the sprite in the new location.

--
So a snake style game would be a hassle to make then? I would have to make up to a 100 invisible sprites to appear, and then  in the code have a counter to calling the next sprite in the list?

--
You might be able to do a snake game with the Canvas DrawLine event rather than sprites.

--
I would have to make up to a 100 invisible sprites to appear, and then  in the code have a counter to calling the next sprite in the list?
Yes. That is the way I would do it.
Keep the component blocks for the ImageSprites in a list from 1 to the number of segments in the snake.

item 1 is the tip of the tail, item n is the head.

Then treat the list as a FIFO queue.

For the snake to move,
 the tip of the tail becomes the new head.
The the old head becomes a body segment.
The second segment becomes the new tail.

The list of components is initially:
item 1 is the tip of the tail
item 2 is the segment after the tip of the tail
(these middle items are body segments)
item n-1 is body segment after the head
item n is the head.

Now, for the snake to move forward one segment,

the list is appended with the value from item 1 to become the new head.
Item 1 is removed.
the new item 1 becomes the tip of the tail.
item n-1 (the old head) becomes a body segment.

Once the component blocks have been set in the list, their respective Images can be set to body segment to tail tip, old head to body segment, tail tip to head.
And the snake redrawn perhaps with a new angle for the head (make sure Rotates is enabled for all ImageSprites)

Each time the snake moves a segment, the process is repeated.

There may be a sinpler way to do it, but this seems a logical way to me.

--