make 2 lists or objects?

oddchild

New member
Joined
Jul 18, 2017
Messages
24
Hi everyone,



I have been working on a game that teaches letters for Syrian Refugee children. turkmani.org/hariflar/

I'd like to make it so that each letter is repeated 3 times so that the player has to learn each letter. This way if they answer a letter correctly three times, it won't get asked again. What would be the best way to do this?

If they click on the correct answer, should I add it to a list of answered correctly list? Then if they get it right twice, remove from list one to list two, and finally to list three. Then when a question is asked it could check list three to see if that letter needs to be asked?

I have not used lists before, so I am not sure how I should do this.

Otherwise I could make each letter an object, though that sounds like it would just make things more complicated.

Thanks
 

MikeHart

Administrator
CX Code Contributor
3rd Party Module Dev
3rd Party Target Dev
3rd Party Tool Dev
Joined
Jun 19, 2017
Messages
3,504
How do you store your information right now?
 

Wingnut

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
1,284
I'm doing something similiar right now . What I do is I initiate an array, where each number represents one letter.
I then pick a random number (which I quickly re-pick if it happens to be zero) and that particular letter in the array gets counted down as long as it its higher than zero. If it's zero i don't touch it I use it as a flag.

This also allows some letters to be more common which is a thing that I use quiet a lot but even
if you do not need that feature it's a good way of doing it I think.
 
Last edited:

oddchild

New member
Joined
Jul 18, 2017
Messages
24
The current version wasn't storing anything but a score. Once the score gets past 8 then the questions are asked from a different set of letters.

question = rnd(score -8, score)

this way questions are not all over the place and move up.
 

oddchild

New member
Joined
Jul 18, 2017
Messages
24
Th
I'm doing something similiar right now . What I do is I initiate an array, where each number represents one letter.
I then pick a random number (which I quickly re-pick if it happens to be zero) and that particular letter in the array gets counted down as long as it its higher than zero. If it's zero i don't touch it I use it as a flag.

This also allows some letters to be more common which is a thing that I use quiet a lot but even
if you do not need that feature it's a good way of doing it I think.
that is a great idea.. I just have no idea of how to implement that.

I also have each letter representing a number. Then they are correlated to a matching mp3 for the sound and matching image file.
 

oddchild

New member
Joined
Jul 18, 2017
Messages
24
right now, I have the four letters as four buttons. Then I generate a different letter for each button making sure that they are not equal to the other buttons.



rndnum = Rnd (level - 7 ,level)
button.ImagePointer(rndnum + mode + ".png")

rndnum2 = Rnd (level - 7, level)

While rndnum2 = rndnum
rndnum2 = Rnd (level - 7, level)
Wend


button2.ImagePointer(rndnum2 + mode + ".png")



rndnum3 = Rnd (level - 7, level)

While rndnum3 = rndnum Or rndnum3 = rndnum2

rndnum3 = Rnd (level - 7, level)

wend

button3.ImagePointer(rndnum3 + mode + ".png")


rndnum4 = Rnd (level - 7, level)


While rndnum4 = rndnum Or rndnum4 = rndnum3 Or rndnum4 = rndnum2



rndnum4 = Rnd (level - 7, level)



Wend



button4.ImagePointer(rndnum4 + mode + ".png")
 

dawlane

Well-known member
CX Code Contributor
Tutorial Author
Joined
Jun 21, 2017
Messages
1,049
Use StringMap<Int> instead of a list for correct answers.
The map key would be used to hold the letter and the value will hold the number of times for a correct answer.
All you do then is check to see if the map contains the key, get that keys value to check against.
 

Wingnut

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
1,284
The current version wasn't storing anything but a score. Once the score gets past 8 then the questions are asked from a different set of letters.

question = rnd(score -8, score)

this way questions are not all over the place and move up.
I simplified my code to show you an example how I do it. Just change the number of unique symbols from 10 to a thousand or whatever you need for your alphabet.

Here I want 10 symbols to appear 3 times each. So I create a sequnce that i can use later and just "eat it up from any direction", one by one, without being afraid it will give me something that I do not want.

Code:
Import mojo2

Function Main ()
    New Game
    Return 0
End 

Class Game Extends App

    Field letters:Int[]
    Field letterpool:Int[]
    Field picked:Int = 0
    Field canvas:Canvas

    Method OnCreate ()
  
        canvas=New Canvas
      
        ' Init statistics of each letter.
        letters=New Int[10]
        For Local i:Int = 0 To 9
            letters[i] = 3
        Next
      
        ' Prepare a pool of random letters.
        Local total:Int = 10 * 3
        letterpool=New Int[total]
      
         ' Pick random letter and make sure that we don't overuse anyone of them.
        Local counter:Int = 0
        Repeat
            picked = Int(Rnd(10)) ' pick integer 0 - 9
               ' If letter is available then add the letter to the sequence pool.
            If letters[picked] > 0
                letters[picked] = letters[picked] - 1
                letterpool[counter] = picked
                counter = counter + 1
            Endif
        Until counter = total ' The sequence pool now has 3 of each letter.
    End

    Method OnRender : Int()
        canvas.Clear
      
      
        ' Example to scroll through the letterpool we created that is containing a sequence of 10 unique letters, each one is used exactly 3 times. The length of it is therefore 30 (index 0-29).
        picked = MouseX() ' read mouse or touch
        If picked < 0 Then picked = 0 ' keep value to positive numbers
        picked = picked Mod 30 ' keep value to max of 29
        ' Show the value
        canvas.DrawText "Lookin inside seq at pos "+ String(picked) + " and it contains the letter id : " + String(letterpool[picked]) ,100,100


        canvas.Flush
        Return 0   
    End
  
End
 
Last edited:

Wingnut

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
1,284
A changed it to use a alphabet consisting of 1000 unique letters.
I still want exactly 3 of each so the sequence it spits out becomes 3000 items long.
It's a simple way but it works for me.

Code:
Import mojo2

Function Main ()
    New Game
    Return 0
End   

Class Game Extends App

    Field letters:Int[]
    Field letterpool:Int[]
    Field picked:Int = 0
    Field canvas:Canvas

    Method OnCreate ()
    
        canvas=New Canvas
        
        ' Init statistics of each letter.
        letters=New Int[1000]
        For Local i:Int = 0 To 999
            letters[i] = 3
        Next
        
        ' Prepare a pool of random letters.
        Local total:Int = 1000 * 3
        letterpool=New Int[total]
        
         ' Pick random letter and make sure that we don't overuse anyone of them.
        Local counter:Int = 0
        Repeat
            picked = Int(Rnd(1000)) ' pick integer 0 - 9
               ' If letter is available then add the letter to the sequence pool.
            If letters[picked] > 0
                letters[picked] = letters[picked] - 1
                letterpool[counter] = picked
                counter = counter + 1
            Endif
        Until counter = total ' The sequence pool now has 3 of each letter.
    End

    Method OnRender : Int()
        canvas.Clear
        
        ' Example to scroll through the letterpool we created that is containing a sequence of 1000 unique letters, each one is used exactly 3 times. The length of it is therefore 3000 (index 0-2999).
        picked = MouseX() ' read mouse or touch
        If picked < 0 Then picked = 0 ' keep value to positive numbers
        picked = picked Mod 3000 ' keep value to max of 2999
        canvas.DrawText "Lookin inside seq at pos "+ String(picked) + " and it contains the letter id : " + String(letterpool[picked]) ,100,100

        canvas.Flush
        Return 0     
    End
    
End
 

oddchild

New member
Joined
Jul 18, 2017
Messages
24
So for it to work with only 31 letters I would change the 1000 to 31?


Thanks for helping me out. I am currently visiting Iraq, I don't exactly have any programing friends out here.
 

Wingnut

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
1,284
You got it, I made one here to get you up to speed. I'm not sure if this is what you are after but it will do the job nicely!

Code:
Import mojo2

Function Main ()
    New Game
    Return 0
End   

Class Game Extends App

    Field letters:Int[]
    Field letterpool:Int[]
    Field picked:Int = 0
    Field canvas:Canvas

    Method OnCreate ()
    
        canvas=New Canvas
        
        ' Init statistics of each letter.
        letters=New Int[31]
        For Local i:Int = 0 To 30
            letters[i] = 3
        Next
        
        ' Prepare a pool of random letters.
        Local total:Int = 31 * 3
        letterpool=New Int[total]
        
         ' Pick random letter and make sure that we don't overuse anyone of them.
        Local counter:Int = 0
        Repeat
            picked = Int(Rnd(31)) ' pick integer 0 - 9
               ' If letter is available then add the letter to the sequence pool.
            If letters[picked] > 0
                letters[picked] = letters[picked] - 1
                letterpool[counter] = picked
                counter = counter + 1
            Endif
        Until counter = total ' The sequence pool now has 3 of each letter.
        ' Print counter
    End

    Method OnRender : Int()
        canvas.Clear
        
        ' Example to scroll through the letterpool we created that is containing a sequence of 31 unique letters, each one is used exactly 3 times. The length of it is therefore 31*3 (93 items, 0-92)
        
        ' Now you have a seq of 93 items that you can use in the game/course one by one. Sorry I don't have time to make a better testcode
but it's all working.

        picked = MouseX()
        If picked < 0 Then picked = 0
        picked = picked Mod 31
        canvas.DrawText "Lookin inside seq at pos "+ String(picked) + " and it contains the letter id : " + String(letterpool[picked]) ,100,100

        canvas.Flush
        Return 0     
    End
    
End
 

oddchild

New member
Joined
Jul 18, 2017
Messages
24
I got lost in the example.. I am thinking what about just an array?

letters[31]

for example when someone gets the letter "b" right it would just add a point to that number in the array.
letters[2] = letters[2] + 1

print "the letter b has " + letters[2] + " points"


I got it work now. now, the game shows each letter 3 times (if correct.) i had to make the game end at 90 even though it should have been able to make it to 93, (31 letters).
 

Paul59

Active member
CX Code Contributor
Joined
Dec 13, 2018
Messages
384
"I'd like to make it so that each letter is repeated 3 times so that the player has to learn each letter. This way if they answer a letter correctly three times, it won't get asked again. What would be the best way to do this?"

If that's all you need to do, a simple way might be to use a string, for example "AAABBBCCCDDD..."

Choose a random letter rnd(length of string), remove that letter from the string (by slicing) and repeat until the string contains no characters.
 
Top Bottom