A few questions

legendofjon

Member
Licensed User
Longtime User
First of all, I would like to take the time and thank everyone for helping out the noobs like me. I spent a considerable amount of time browsing through the forum and reading past issues that were resolved.

Now i only know python and partially, and for that reason adapting myself to basic4android might take some time. Anyways,

I have many problems:
1) I am trying to set 2 conditions in a If statement
In python i would write
B4X:
If x = 6 or x < 10 #execute the following
Unfortunately, this does not seem to work.
So I tried to do the following instead:
B4X:
If x = 6 Then
      
      Msgbox("something", "title")
      Activity.LoadLayout("level2")
      If L_Points = 10 Then
         
         Msgbox("something", "title")
         Activity.LoadLayout("special")
      End If
   End If
But then what happens is that the second If statements overlaps with the first one. In other words, the second if statements does not execute properly.

2) Random Positions
I have an item, and want it to be placed at random places on the screen, but specified random places. Here's what i mean,
B4X:
   item.Left = Rnd(100, 105) OR Rnd(10, 11)
           item.top = Rnd(0, 10) OR Rnd(15,30)
The first random for left and top shows that it will appear within that area, while the second random for left and top shows it will appear within another area. However, when my app launches it will appear at one of those two area (or more if i add more random).

3)Hide Keyboard
After the user type the number in the box, i want to keyboard to automatically disappear when they click on the submit button, without them having to hit the back button and keyboard will only reappear when they click on the text box again, and disappear once they click on the submit button.

For some reason, the Phone.hidekeyboard suggested by your peers doesn't seem to work for me. I am running on v2.3 and do not seem to have the Phone library (Phone is red and not blue). I do not know how to get Phone to work, or if there's any alternative.

3.5) Adding a timer to type something
Let's say, at a level, i want the user to have only 10 seconds to type something, or else the keyboard disappear and they lose a point. I know how to handle the point system, just that i do not know how to time the keyboard.

4) How do i change the look of the message box?
That is, from the standard look that is based on the user phone design, to a more unique one that will look the same for everyone. For example, message box with blue color as background, or something like that. Later on change the look of the message box to reflect the visual design of the level. Would it be possible to do the same with the keyboard?

5) Changing the color of the text box field
By default, it is white. But lets say i want to change it to something more vibrant like green, would that be possible?

6) What is the code to play music as a background in my app?
I would also use that code to play a different music, at a different level.

I thank in advance everyone who takes the times to try and assist me on many of my problems.
:sign0163:
 

KitCarlson

Active Member
Licensed User
Longtime User
I have found the beginners guide, user guide, tutorials, B4Awiki, and searching the forum, are all quite helpful. By re-reading the guides, it amazing how in a different light, more becomes apparent. The difficult part for me is learning the terminology, once that is learned, it is easier to search and apply methods.
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
I'm pretty sure the docs will answer all of your questions. Let us know if they don't...
 
Upvote 0

legendofjon

Member
Licensed User
Longtime User
Many of my problems were in deed solved from reading the documentation. However, i still have a dilemma with the following:

Randomly positioning an item. I know how to position an item, but for me to use "Or", or any boolean expression i have to use something like If or For statements, which i don't really see the purpose of setting up a condition when i just want my item to be randomly placed on the screen by randomly selecting a pre-determined area.
item.Left = Rnd(100, 105) Or Rnd (54, 200)
item.top = Rnd(15,30) Or Rnd (45, 300)
 
Upvote 0

KitCarlson

Active Member
Licensed User
Longtime User
I will try to help. I think you problem have to do with understanding a Boolean operation. This is more to due with logic, and computer languages in general not B4A.

The OR is used with Boolean operators. Boolean operators have only two states, True (1) or False (0). An random number representation is not Boolean. The value could be 1 or 0, however general type of number is not. Operations often require specific types of operators. An example is if counting only apples, what is done with an orange or tennis ball. An error occurs.

An expression of (x = 10) is True if x, has the value of 10.

An OR expression of A = B OR C, A is True if either or both C and B are True and False if both C and B are False. Then think of B as (x=10), then if X have the value of 10 B is True, and if x is not 10, it is False. So the comparison results in a Boolean result.

With all respect, your statements are not logical. I am sure by additional searching and study of Boolean operators you will understand.
 
Upvote 0

legendofjon

Member
Licensed User
Longtime User
It would be easier to help you if you explained exactly what you want to do !
The code snippets you posted won't work but I don't understand what they are supposed to do.

Best regards.

Il try and elaborate a bit.

I have an item and I want that item to be randomly placed on the screen. But i do not want to be placed anywhere (like on the buttons, and text field input). So i associated with many "areas" or possible places where the item could appear.

Now the code,
item.Left = Rnd(100, 105) Or Rnd (54, 200)
item.top = Rnd(15,30) Or Rnd (45, 300)

I was setting the item.left various possible position. Where the first Rnd(100, 105) would tell the system to display the item within that range. And the second one as well. And the "OR" meant to select one of the two area for left. Same principle for top.
But like KitCarlson specified i cannot do that.

I dont know if i am more clear or not.

Thanks
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
How should the selection between the first and the scecond area be done ?
If it should also be done randomly then you could use this code:
B4X:
If Rnd(0, 2) = 0 Then
    item.Left = Rnd(100, 105)
    item.top = Rnd(15,30)
Else
    item.Left = Rnd (54, 200)
    item.top = Rnd (45, 300) 
End If

'or

If Rnd(0, 2) = 0 Then
    item.Left = Rnd(100, 105)
Else
    item.Left = Rnd (54, 200)
End If

If Rnd(0, 2) = 0 Then
    item.top = Rnd(15,30)
Else
    item.top = Rnd (45, 300) 
End If
Best regards.
 
Upvote 0

legendofjon

Member
Licensed User
Longtime User
How should the selection between the first and the scecond area be done ?
If it should also be done randomly then you could use this code:
B4X:
If Rnd(0, 2) = 0 Then
    item.Left = Rnd(100, 105)
    item.top = Rnd(15,30)
Else
    item.Left = Rnd (54, 200)
    item.top = Rnd (45, 300) 
End If

'or

If Rnd(0, 2) = 0 Then
    item.Left = Rnd(100, 105)
Else
    item.Left = Rnd (54, 200)
End If

If Rnd(0, 2) = 0 Then
    item.top = Rnd(15,30)
Else
    item.top = Rnd (45, 300) 
End If
Best regards.

Thank you so much, but now it prompt this error

Compiling code. Error
Error compiling program.
Error description: Object expected.
Occurred on line: 65
item.Left = Rnd(100, 105)
Word: left

I set up item as an integer and assigned it with the following
Points.Text = item

thanks and happy new year
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Unfortunately as you didn't explain further more what you did impossible to help you.
In my mind item was in object with Left and Top properties.

When you ask for help you should explain more in detail what you want to do and what you already did.

What is item, and how did you declare it ?
What is Points and how did you declare it ?
Does the Points object what ever it is have a Text property ?

Without knowing all this how are we supposed to help you.

To get quick help the most efficient way is to post your project as a zip file or at least a smaller one that shows the problem.

Best regards.
 
Upvote 0

legendofjon

Member
Licensed User
Longtime User
Unfortunately as you didn't explain further more what you did impossible to help you.
In my mind item was in object with Left and Top properties.

When you ask for help you should explain more in detail what you want to do and what you already did.

What is item, and how did you declare it ?
What is Points and how did you declare it ?
Does the Points object what ever it is have a Text property ?

Without knowing all this how are we supposed to help you.

To get quick help the most efficient way is to post your project as a zip file or at least a smaller one that shows the problem.

Best regards.

Hello
sorry for the late reply. I was terribly sicked, and had family issues.
Now to answer your questions,

I have paste a very good portion of my code below

B4X:
Sub Globals

   Dim confirmbutton, btn0 As Button
   Dim totalcount As Label
   Dim infobox As Label
   Dim randomnumber As Label
   Dim Label_Points As Label
   Dim Number1, L_Points As Int
   
End Sub
B4X:
Sub New
   Number1 = Rnd(1, 25)         
   randomnumber.Text = Number1   
   randomnumber.TextColor = Colors.Blue
   randomnumber.Left = Rnd(100, 105)
   randomnumber.Left = Rnd(10, 11)
   randomnumber.top = Rnd(0, 10)
   randomnumber.top = Rnd(15,30)
   infobox.Text = "Type the numbers below" & CRLF & "and click on FIND"
   infobox.Color = Colors.RGB(204,255,255)   
   totalcount.Text = ""            
   btn0.Visible = False
   Label_Points.Text = L_Points
   If Rnd(0, 2) = 0 Then
        L_Points.Left = Rnd(100, 105)
        L_Points.top = Rnd(15,30)
   Else
        L_Points.Left = Rnd (54, 200)
        L_Points.top = Rnd (45, 300) 
   End If

   'or

   If Rnd(0, 2) = 0 Then
        L_Points.Left = Rnd(100, 105)
   Else
        L_Points.Left = Rnd (54, 200)
   End If

   If Rnd(0, 2) = 0 Then
        L_Points.top = Rnd(15,30)
   Else
        L_Points.top = Rnd (45, 300) 
   End If
   
   If L_Points = 2 Then 
      infobox.Text = "Good job. You are awarded with 2 points" & CRLF & "Click on MORE to continue"
   
   Else If L_Points = 4 Then
      infobox.Text = "Congradulation! You are awarded with 2 points" & CRLF & "Click on MORE to continue"
   Else If L_Points = 6  Then
      infobox.Text = "Amazing! 2 more points were added" & CRLF & "Click on MORE to continue"
   Else If L_Points = 8  Then
      randomnumber.TextColor = Colors.Red
   End If
   End Sub
   

Sub CheckResult
   If totalcount.Text = Number1  Then
      L_Points = L_Points + 2
      infobox.Color = Colors.RGB(128,255,128)   
      btnAction.Text = "MORE"
   Else
      Label_Points.Text = L_Points
      infobox.Text = "Nice try, keep looking" & CRLF & "Enter a new result" & CRLF & "and click FIND"
      infobox.Color = Colors.RGB(255,128,128)   
   End If
End Sub

If you need anything else, let me know and thanks
 
Upvote 0

legendofjon

Member
Licensed User
Longtime User
Sorry, but you still didn't explain what you want to !
Could you post the code as a project zip file (IDE menu Files / Export As Zip)

Best regards.

Ok, i have attach my game. To help you get a sense of what i am trying to do. I brought my game which is like 2% done to working condition. So you would be able to run it, and get a sense of what I am trying to do, and what i meant by randomly placing the number you will have to guess at random (makes it fun) selected areas (to not block inputs).

If you need more info, let me know
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
Sorry, but I still don't understand what exactly you want to do with randomly positioning with two regions?
Couldn't you explain with a few sentences what the behaviour should be.

What are these lines supposed to do ?
B4X:
randomnumber.Left = Rnd(100, 105)
randomnumber.Left = Rnd(10, 11)
randomnumber.top = Rnd(0, 10)
randomnumber.top = Rnd(15,30)
You set the Left and Top postitions twice.
The second line overrides the first one.

Best regards.
 
Upvote 0

legendofjon

Member
Licensed User
Longtime User
Sorry, but I still don't understand what exactly you want to do with randomly positioning with two regions?
Couldn't you explain with a few sentences what the behaviour should be.

What are these lines supposed to do ?
B4X:
randomnumber.Left = Rnd(100, 105)
randomnumber.Left = Rnd(10, 11)
randomnumber.top = Rnd(0, 10)
randomnumber.top = Rnd(15,30)
You set the Left and Top postitions twice.
The second line overrides the first one.

Best regards.

Oh yea, i set left and top positions twice because i wanted the system to randomly chose one of them. But then i remember that, it would only chose the most recent as the most recent would replace the first.

When you run my program you see in the background numbers all around the corners. The random number would appear somewhere there. Thats what i meant by randomly positioning. Now i do not want it to randomly appear behind a text field or buttons, so thats why i was trying to set up pre-determined places it could appear, and then randomly select from those pre-determined space. So its like random, but controlled random.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Is this what you are looking for ?
B4X:
If Rnd(0,2) = 0 Then
    randomnumber.Left = Rnd(100, 105)
    randomnumber.top = Rnd(0, 10)
Else
    randomnumber.Left = Rnd(10, 11)
    randomnumber.top = Rnd(15,30)
End If
This is exactly the same as I suggested you in post #10.

Best regards.
 
Upvote 0

legendofjon

Member
Licensed User
Longtime User
Is this what you are looking for ?
B4X:
If Rnd(0,2) = 0 Then
    randomnumber.Left = Rnd(100, 105)
    randomnumber.top = Rnd(0, 10)
Else
    randomnumber.Left = Rnd(10, 11)
    randomnumber.top = Rnd(15,30)
End If
This is exactly the same as I suggested you in post #10.

Best regards.

Ah yes, thank you. It is working now, i guess it was badly pasted. On a side note, i tried adding a third and fourth possibilities, but it doesnt seem to accept Else If statements such as
B4X:
If Rnd(0,2) = 0 Then
    randomnumber.Left = Rnd(100, 105)
    randomnumber.top = Rnd(0, 10)
Else If
    randomnumber.Left = Rnd(300, 205)
    randomnumber.top = Rnd(50, 100)
Else
    randomnumber.Left = Rnd(10, 11)
    randomnumber.top = Rnd(15,30)
End If

thanks

and my last question for now is the following (i know you did so much already)
I want to user to go back to a page after failing to guess the number either more than three times in a row or 5 times in general (counting the two times in a row) and with the score being saved into a database (for highscores).
I will be completly honest. I am completly incompetent and do not know how to start. I did however start with this

B4X:
Sub CheckResult
   If totalcount.Text (total count being the number inputed) != Number1 (the random number)  Then
           Activity.LoadLayout("Main") #meaning they quit and go back to home page

I know i need to learn more
 
Last edited:
Upvote 0

legendofjon

Member
Licensed User
Longtime User
I want to user to go back to a page after failing to guess the number either more than three times in a row or 5 times in general (counting the two times in a row) and with the score being saved into a database (for highscores).
I will be completly honest. I am completly incompetent and do not know how to start. I did however start with this

B4X:
Sub CheckResult
   If totalcount.Text (total count being the number inputed) != Number1 (the random number)  Then
           Activity.LoadLayout("Main") #meaning they quit and go back to home page

I know i need to learn more

OK, I manage to fix my first issue (adding more possibilities), but im stuck on the second one, so far i have done this
B4X:
If totalcount.Text(Number1) = False Then
   If totalcount.Text(Number1) = False Then
      If totalcount.Text(Number1) = False Then
         Msgbox("game over", "fdsd")
                        Activity.LoadLayout("Main")
        End If
           End If
End If
now i do not want the user to quit on the first time it doesnt equal, but either when he fails to identify the number 3 time in a row, or 5 times overall.

for my second issue. In python, there is something call dictionary. I was thinking of appending all the scores to a dictionary (with the key being their name, and the value the score), and then when they hit on high score on main screen, that would just pull out the dictionary. Would this be feasible in basic4android?

Thanks
 
Last edited:
Upvote 0
Top