2017년 3월 26일 일요일

Drag and swap of two canvas error


I want to drag and swap two canvas separately in 1 screen. I am getting error "End Application". I think some think i do wrong in namemap or set-sprite-size.



















--
Your set_sprite_sizes procedure sets heights and widths of each sprite to a list?
Heights and widths are supposed to be numbers.

--
Also, the drag and touchUp events for your new 9 sprites are wierd - 
They try to drag the matching sprite from the first set of 9 sprites?
Please explain.

-- 
You will need a new procedure to tell you which canvas component a sprite component belongs to.
That should help set_sprite_sizes know which canvas's proportions to use when it sets sprite sizes,
sprite by sprite.

-- 
"Your set_sprite_sizes procedure sets heights and widths of each sprite to a list?
Heights and widths are supposed to be numbers."
Now i understand. Beginner mistake.


"Also, the drag and touchUp events for your new 9 sprites are wierd - 
They try to drag the matching sprite from the first set of 9 sprites?
Please explain."

Another mistake. I forgot to change  the i.s.


"You will need a new procedure to tell you which canvas component a sprite component belongs to.
That should help set_sprite_sizes know which canvas's proportions to use when it sets sprite sizes, sprite by sprite."

I will try. I try to make defalt canvas, like anysprite, something like any canvas.

--
I try to work with enable sprite to move one bye one, i try to make a procedure, but i think that procedure is to complicate for me.  I will keep trying, i want give up. Thanks a lot for your time and help.


--
Here are some procedures you will need ...

all_canvas1_sprites():
returns a list of just the  sprites that are in canvas1

all_canvas2_sprites():
returns a list of just the  sprites that are in canvas2

(The Duplicate facility makes these easy to build from the all_sprites function,
just make a duplicate, change its name, and snip off the sprites that don't belong,
along with their sockets)

canvas(sprite):
takes a sprite component as input, and returns either the Canvas1 component or the Canvas2 component,
depending on the input sprite...
return (
   if is_in_list(all_canvas1_sprites(), sprite) THEN
      canvas1  ELSE
   if is_in_list(all_canvas2_sprites(), sprite) THEN
      canvas2  ELSE
   (something went wrong, return 0 and crash)

Use the canvas(sprite) function to tell you which canvas's size to use when looping through all your sprites setting their sizes.

--
Ok. Thank you for your help. I do what you said, but something i do bad and i dont see what. Please help. Thank you.

--
You didn't say what is going wrong.

You didn't say why you need two canvases.

You have a scrollable screen, and I don't know how  it is possible to drag sprites on a canvas on a scrollable screen.

You didn't say what the object of the puzzle is.

How can I know how to help you?

--
1.Now the sprite want drag.
2. If is an puzzle, i start with canvas1, then canvas2 will be hidden.

--
He has text and buttons and dont feet the screen.When one of the canvas will be visible, other will be invisible.

--
So I expect you will then come back and ask for a third screen and then a fourth screen
or a third canvas and then a fourth canvas as you keep adding more puzzles?

You are going to present only one puzzle at a time, and each puzzle will
consist of just one canvas full of blocks, right?

That means you have to reuse the one canvas and the 9 sprites with
a different set of images and a different set of starting locations for
the new set of images.

Build a spreadsheet with the puzzle numbers, row numbers, column numbers, and image file names,
export it as a csv file, upload it into your Media drawer, and load it from a File at puzzle startup time.

You will also have to keep some way of telling how to know if the puzzle has been solved.

You haven't told us that yet.

--
"So I expect you will then come back and ask for a third screen and then a fourth screen
or a third canvas and then a fourth canvas as you keep adding more puzzles?

You are going to present only one puzzle at a time, and each puzzle will
consist of just one canvas full of blocks, right?"
I only search for help when i have a problem.



"That means you have to reuse the one canvas and the 9 sprites with
a different set of images and a different set of starting locations for
the new set of images."
That is a good idea and i was trying do it this way.

"Build a spreadsheet with the puzzle numbers, row numbers, column numbers, and image file names,
export it as a csv file, upload it into your Media drawer, and load it from a File at puzzle startup time."

"You will also have to keep some way of telling how to know if the puzzle has been solved."
I gues i have to put a picture. :)

Thank you very much for your help and understanding.
Regards C.G.

That is my idea.

--
"You will also have to keep some way of telling how to know if the puzzle has been solved."
I guess i have to put a picture. :)
You could keep the solution with the puzzle in the puzzle file,
using an extra column: "P" = Puzzle, "S" = Solution.

Columns:

Puzzle number,
P/S (Puzzle or solution?),
row number,
column number,
image file name

Assuming all puzzles are 3 by 3,
Each puzzle and its solution would  take up 18 (9+9) rows
of this 5 column table.

Row and column numbers 1-3 are more device-independent 
than px and py values, and can be easily converted back and forth
px(row) = 1 + ((row-1) * (Canvas1.Width / 3))
py(col) = 1 + ((col-1) * (Canvas1.Height / 3))

-- 
Your idea is not bad, but is too complicate allready. I am a beginner, i dont know programing coding. I learn with my teacher google and do what i can. I use a hint button to show how the puzzle should look(more easy for me).I will try what you said. Thank you very much.

--
Combine load and load all sprites = first time check. In example i try this formula to work for save 2 puzzles. Theoretically should work. I rename first time check in puzzle 1, i duplicate that in puzzle2(put even a TDB2). And when i press next then i put puzzle2 check to storage save puzzle2 in there. But dont work. I use 1 screen, 1 canvas.
I have one question, why puzzle1 and puzzle 2 dont work ?












--
Tinydb2 is the same place as TinyDB1.
They both go to the same place.
If you store something under a tag in TinyDB1, you will find it under that same tag in TinyDB2.

Also, where do you put the sprites in the proper places on the canvas at the start of a puzzle?

Also, where you keep track of which puzzle you are currently running?

--
"Also, where do you put the sprites in the proper places on the canvas at the start of a puzzle?"
I have start coordinates.

"Also, where you keep track of which puzzle you are currently running?"
Is Next button, to switch puzzle ?

--
I have one question, why puzzle1 and puzzle 2 dont work ?
Besides the TinyDB1 and 2 problem, there's nothing obvious from the blocks.

After you fix the TinyDB problems,
and after you test again,
tell us in detail what you expect to happen when you do what and what happens instead.

-- 
Ok, i try this formula. 1 puzzle is ok i go next is ok when i go back all puzzle are the same, when i move puzzle 1, puzzle 2 move two. The Tinydb of the tag is not ok ?










--
In puzzle_check procedure, you are using a list as a Tinydb tag?

What does that mean?

Explain.

-- 
I was trying to use 1 procedure for store data for puzzle 1 and puzzle 2.

--
Do a right-click-DoIt on the Get TinyDB in that procedure, to see what was stored under that tag, to see why that doesn't make sense.

-- 
I try to make this work for days, but i cant. I try millions of formula, but not succed. My questions is: It is possible to save data for different tags ? It is possible to save data for different tags of the same thing ?
The only problem i have is tinydb.










--
Would you like to post your .aia to the forum, for me to rework?

I am looking for a sample project to introduce JSON puzzle storage in a tutorial.

It would need to include at least 2 puzzles.

--
I make this sample project. You can use and work with that and do what ever you want. It is the same like my project only has different fotos, and some buttons.


--
It occurred to me that the swap operation when letting go of a sprite onto another sprite doesn't need to swap the sprites,
but only their images.  The dragged sprite need only go back to where it was when the puzzle was loaded, and
the current state of the puzzle can be represented as an ordered list of the images file names
in sprites I1, I2, ...., I9 .

Judging the completion of the puzzle can be done by comparing the current state of the puzzle
against the pre-determined list of image files names in the solution.
(There might be a list comparison block that can do it, it needs checking.)

Keeping just the ordered list of image file names is much simpler than keeping sprite positions.

By the way, you never said what the objective of the puzzle was - 
something involving the colors of the tiles and their central dots?

--
"By the way, you never said what the objective of the puzzle was - 
something involving the colors of the tiles and their central dots?"
In that example is simple, to put in order the number of the each picture, 1-9(puzzle resolv)

"
It occurred to me that the swap operation when letting go of a sprite onto another sprite doesn't need to swap the sprites,
but only their images.  The dragged sprite need only go back to where it was when the puzzle was loaded, and
the current state of the puzzle can be represented as an ordered list of the images file names
in sprites I1, I2, ...., I9 ."
I think when is a lot of puzzles that is  more complicate(more code to write).

--
I try to make a save button and not save automatically, but i have the same problem. I think the only way is to have 2 different database.

--
 I think the only way is to have 2 different database.
Though you may have dragged 2 copies of TinyDb out from the Designer, they are the same place under two different names.

Adding a tag to one will result in the same tag in the other database.

The trick here is to extend your tags with the puzzle number to keep them separate.

So instead of keeping sprite1X,sprite1Y, sprite2X,  sprite2Y, sprite3X, sprite3Y  for puzzle 5, keep
P5sprite1X, P5sprite1Y, P5sprite2X, P5sprite2Y,P5sprite3X,P5sprite3Y
where I added P5 in front of the tags for puzzle 5.

That keeps the TinyDB for all the puzzles separate.

--
I try to make puzzles with 1 canvas, but i cant manage to save in 1 tinydb. Now i try to make with 2 canvas, i make it save the coordinates of the sprites, but in canvas 2 the sprites dont take places in the exacly coordinates like canvas 1 and when i close apk and start again, canvas 1 is saved, but canvas 2 have all sprites together. Is something wrong in this blocks ?



--
See attached for how to do this with files of puzzles and answers.
(Answer checking not implemented.)
Thank you very much. I see you make in another way and is better. I guess, answer is, when the puzzle is complete. I will try to make this procedure. I will make a procedure call puzzleresolve and i put the coordinates for complete puzzle. When the sprite have this coordinates, wiil show a pic or text puzzleresolve or complete. 

--
This is an entirely new way of "moving" the sprites.

The sprites don't move.  They just snap back into their original position,
but they exchange the Sprite.Picture values with their target sprites,
giving only the appearance of having switched places.

This changes the record keeping, making it much simpler.

Every sprite stays at the same (X,Y) is started out.

The only thing that changes is the way the image file names are assigned to the 
sprites.  
This is just a list of image file names, in order of which sprite they are in
(I1, I2,...I9).

Look in TinyDB at tage Puzzle1, and you will see it has a list of image file names.
Do a few drag and swap operations, and look again, and you will see how that list changes.

The initial setting is loaded from text file Puzzle1.txt in the Media drawer.
I left another file there too, named Answer1.txt, as an example of how to keep the answer for Puzzle1.

There is no storage of (X,Y) values in TinyDB any more.

-- 
"I left another file there too, named Answer1.txt, as an example of how to keep the answer for Puzzle1."
Answer1.txt it should show when the puzzle is resolve ? For now is no procedure for answer1.txt ?!
It is posible when puzzle is resolve (Answer1.txt) to show: a picture, text, video,etc. ?

--
Answer1.txt it should show when the puzzle is resolve ?
By now, you should have opened up Answer1.txt in a text editor like Notepad to see what's in it.
I took the lazy way out and did not rearrange the image file names in it to match your solution,
because I was not sure what the solution is to Puzzle1.txt..

It is up to you to shuffle the contents of Answer1.txt into the proper order, to match your intended
solution to Puzzle1, and upload the corrected copy into the Media Drawer.
For now is no procedure for answer1.txt ?!
The secret trick is to examine the two lists TinyDB1("Puzzle1") and 
the list in Answer1.txt to see if they are the same.  An easy way to compare two lists is to
take csv_from_list of each list to make a text, and compare the texts.

You will have to read the current Answer file based on the file name in the current row of the puzzles table, column 3.
(you have examined the contents of puzzles.txt already, I hope.)

I had to leave SOMEthing for you to program.
It is posible when puzzle is resolve (Answer1.txt) to show: a picture, text, video,etc. ?
Whatever you would like to program.
See the Books and Tutorials section of my FAQ:
There are lots of games in the AI2 Gallery you can examine too.

--
"By now, you should have opened up Answer1.txt in a text editor like Notepad to see what's in it.
I took the lazy way out and did not rearrange the image file names in it to match your solution,
because I was not sure what the solution is to Puzzle1.txt.."
Yes i  open it and the Puzzle 1 have the same order with Answer1, that i dont get it then( answer1.txt have the right order to resolve puzzle). But i dont understand what Answer1 do ?

"It is up to you to shuffle the contents of Answer1.txt into the proper order, to match your intended
solution to Puzzle1, and upload the corrected copy into the Media Drawer."
They was in  order. To complete Puzzle1 , must put numbers in order from 1-9.

"The secret trick is to examine the two lists TinyDB1("Puzzle1") and 
the list in Answer1.txt to see if they are the same.  An easy way to compare two lists is to
take csv_from_list of each list to make a text, and compare the texts."
Where is csv ?

"You will have to read the current Answer file based on the file name in the current row of the puzzles table, column 3.
(you have examined the contents of puzzles.txt already, I hope.)"
Where is cuurrent Answer ? I have examinate all file the first time you post.
Believe me when i say: i read and search  a lot, before i get help.

--
I try to make a Hint with the same method of yours. I try to duplicate and change some names to replace canvas with image, but i get some error: Bad argument to length of list cannot accepte the arg image@2e8877cff
Something is wrong or i have to change, but what ?

drag_and_swap_of_2_puzzles_v7.aia

















--
Here's a short answer, I can answer quickly ...

You can simplify the loading of the Hint image file name by including it as the 4th column of the Puzzles table, in the Puzzles.txt file ...

The begin_load procedure is the place to pick up the hint image file name from column 4 of the puzzle table, and assign it into the Hint image component.




-- 
"The begin_load procedure is the place to pick up the hint image file name from column 4 of the puzzle table, and assign it into the Hint image component."
That is the hard part. :D
I try to do this way (see blocks) , but i geting an error. I have to make another begin_load procedure ? 







--
I try to do this way (see blocks) , but i geting an error. I have to make another begin_load procedure ?
No.

You included one hint image for each puzzle.

There is no need for a Hint number variable.
There is no need for a hints.txt file.
There is no need for a hint1.txt file. or a hint2.txt file.
The image file name for the puzzle1 hint image is at the end of the row in games table current row.

Learn to work with lists.

This advice works for the people Taifun helps, so I will copy it here ...

A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook   http://www.appinventor.org/book2 ... the links are at the bottom of the Web page.  The book 'teaches' users how to program with AI2 blocks.
There is a free programming course here http://www.appinventor.org/content/CourseInABox/Intro  and the aia files for the projects in the book are here:  http://www.appinventor.org/bookFiles  
How to do a lot of basic things with App Inventor are described here:  http://www.appinventor.org/content/howDoYou/eventHandling  .

Also do the tutorials http://appinventor.mit.edu/explore/ai2/tutorials.html to learn the basics of App Inventor, then try something and follow the
 Top 5 Tips: How to learn App Inventor

You will not find a tutorial, which does exactly what you are looking for. But doing the tutorials (not only reading a little bit) help you to understand, how things are working. This is important and this is the first step to do.

--
"The image file name for the puzzle1 hint image is at the end of the row in games table current row."
Ok. The problem is the imagehint show in my emulator, but when i install the apk in my phone, the image hint not show. Do you know why ?






drag_and_swap_of_2_puzzles_v6.aia

--
I have no ideas on the phone vs  emulator hint image file display difference, aside from maybe the automatic size might be a problem.

Or it might be a TinyDB first run initialization problem on a new device.

See this doc for a new version of the app based on JSON puzzle storage,
with full explanations.

Source link in the Gallery is included. Drag and Swap Puzzles in JSON

This is the sprite cannibalism and JSON tutorial I mentioned a few posts ago.

--
I see you make newer version of this game.Is a little bit different. :)
I corrected the pictures of the hint, you can see in the attached project. I dont know if you like this, but i change and i put next and back buttons invisible when the hint is on and visible when the hint is off. You can use it whatever you like. I edit puzzle1.json and puzzle2.json with notepad++. When puzzle start to not be resolve. I dont know if you know what i mean.

Thank you very much. For now all my problem is gone. I dont have more idea for this project for the moment. Thank you for your help and understanding.

dragandswapJSON.aia

--

댓글 없음:

댓글 쓰기