2 problems

derez

Expert
Licensed User
Longtime User
while writing a game for my grandchildren I had two problems that "entertained" me for quite a long time:
1. Adding a view twice:
by mistake I added a scrollview twice to the activity. After selection of an image, the SV is changed to become invisible and then the game goes on. What happened is that one of the SV stayed visible but teransparent and covered the activity screen from sensing the touch, disabling the game. After removing the second addition - everything works. The compiler should have said something, isn't it ?
2. using RandomAccessFile
I used this type of file, with the new WriteObject and ReadObject, to save a special type
B4X:
Type Shapeposition(cx As Int, cy As Int, rotation As Int )
Dim pos(7), ref(7) As Shapeposition
It works very efficiently-
B4X:
raf.Initialize(File.DirRootExternal & "/tangram","sets.dat",False)
ref = raf.ReadObject(name_index*kstep)
raf.Close
But when I changed the name of the program it didn't read the file anymore.
Looking inside I found that the data includes the name of the program:
Zwt dudu.tangram.main$_shapepositionw q ~ wsq ~ wq ~ wsq
, so when the program name is changed - it is unusable, unless re-writing it.
 

derez

Expert
Licensed User
Longtime User
1. How did you add the view twice? Can you post the code?
The first declaration was in create_views which is called from activity_create, and there was also a sub called from there , named sv_init, in which I added all the images. Then I decided to init the SV and add it to the activity in this sub. As I worked on two programs together (one for design and the other to play) - I ended with the initialization and addition to the activity in both places.

B4X:
Sub Activity_Create(FirstTime As Boolean)
activity.LoadLayout("Tangram")
....
create_views
End Sub

Sub create_views
...
[B]sv.Initialize(1.5*activity.height)
activity.AddView(sv,0,0,activity.Width,activity.Height)[/B]
sv_init
end sub

sub sv_init
[B]sv.Initialize(1.5*activity.Height)
activity.AddView(sv,0,0,activity.Width,activity.Height)[/B]
sv.Panel.Width = activity.Width
sv.Panel.Color = Colors.black
sv.BringToFront
...
end sub

I remember that when I tried to use the touch on the activity, I saw the sliding bar of the SV moving (without any images on the SV since the first one was with visible = false).
 
Last edited:

derez

Expert
Licensed User
Longtime User
It is completely valid to use the same variable to add multiple views
It was done by mistake !
If you do that, how do you refer to each of the multiple views ?

you can use 100%x instead of Activity.Width
I know that, but it is clearer to understand.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Cookies are required to use this site. You must accept them to continue using the site. Learn more…