iOS Question Weired Issue - Unable to compile

narek adonts

Well-Known Member
Licensed User
Longtime User
I have a strange issue

I created a code in b4j and now I copied it in my b4i module but the compiler does not compile it. It give some strange error cods

This is the code module

B4X:
'Static code module
Sub Process_Globals
    Type Card (Mast As Int,Rank As Int,id As Int)
    Type Deck (Deck1 As List,Deck2 As List,Deck3 As List,Deck4 As List, AsList As List)
    Type Bonus (BonusType As Int,BonusCards As List)
End Sub

Sub CreateDeck As Deck
   
    Dim WholeDeck As List
    WholeDeck.Initialize
   
   
    For i= 1 To 4
        For ii = 1 To 8
            Dim tmpCard As Card
            tmpCard.id=i & ii
            tmpCard.Rank=ii
            tmpCard.Mast=i
            WholeDeck.Add(tmpCard)
        Next
    Next
   
   
   

    Dim Decks As Deck
    Dim tmpDecks As List
    tmpDecks.Initialize
    Decks.Initialize
   
   
    For i = 1 To 4
        Dim tmpDeck As List
        tmpDeck.Initialize
       
       
        For ii = 1 To 8
           
            If WholeDeck.Size>1 Then
                Dim rndCardId As Int=Rnd(1,WholeDeck.Size)
                tmpDeck.Add(WholeDeck.Get(rndCardId-1))
                WholeDeck.RemoveAt(rndCardId-1)
            Else
                tmpDeck.Add(WholeDeck.Get(0))
            End If
           
        Next
       
        tmpDeck.SortType("id",True)
        tmpDecks.Add(tmpDeck)
       
    Next
   
   
    Decks.Deck1=tmpDecks.Get(0)
    Decks.Deck2=tmpDecks.Get(1)
    Decks.Deck3=tmpDecks.Get(2)
    Decks.Deck4=tmpDecks.Get(3)
    Decks.AsList=tmpDecks
    Return Decks
End Sub


Sub CardPower(card As Card, Xoz As Int) As Int
    If Xoz=5 Then
        If card.Rank=4 Then
            Return 8
        else if card.Rank=8 Then
            Return 9
        Else
            Return card.Rank
        End If
    Else
       
        If card.Mast=Xoz Then
           
            If card.Rank=3 Then
                Return 22
            else if card.Rank=5 Then
                Return  23
            else if card.Rank=8 Then
                Return  21
            else if card.Rank=4 Then
                Return  20
            Else
                Return card.Rank+10
            End If
        Else
            Return CardPower(card,5)
        End If
    End If
   
End Sub


Sub CanPlay (Card As Card,Hand As List,inCards As List, Xoz As Int) As Boolean
   
    If inCards.Size=0 Then
        Return True
    Else
        Dim FirstCard As Card=inCards.Get(0)
       
        If Xoz=5 Then
            If Card.Mast=FirstCard.Mast Then
                Return True
            Else
                Return Not(MastExist(Hand,FirstCard.Mast))
            End If
       
        Else
            If MastExist(Hand,Xoz)=False And MastExist(Hand,FirstCard.Mast)=False Then Return True
           
            If FirstCard.Mast<>Xoz Then
                If Card.Mast=FirstCard.Mast Then
                    Return True
                Else
                    If MastExist(Hand,FirstCard.Mast) Then
                        Return False
                    Else if CardPower(Card,Xoz)> StrongestCardPower(inCards,Xoz) Then
                        Return True
                    Else
                        If StrongestCardPower(Hand,Xoz)<= StrongestCardPower(inCards,Xoz) Then
                            Return True
                        Else
                            Return False
                        End If
                       
                    End If
                End If
           
           
           
            Else
                If Not(MastExist(Hand,FirstCard.Mast)) Then
                    Return True
                Else
                    If Card.Mast<>Xoz Then
                        Return False
                    Else
                        If CardPower(Card,Xoz)> StrongestCardPower(inCards,Xoz) Then
                            Return True
                        Else
                            If StrongestCardPower(Hand,Xoz)<= StrongestCardPower(inCards,Xoz) Then
                                Return True
                            Else
                                Return False
                            End If
                        End If
               
               
               
                    End If
                       
                End If
               
            End If
           
           
       
        End If
       
   
           
           
       
    End If
   
End Sub

Private Sub StrongestCardPower(Cards As List,Xoz As Int) As Int
    Dim MaxCard As Int
    For i= 0 To Cards.Size-1
        Dim crd As Card=Cards.Get(i)
       
        If CardPower(crd,Xoz)> MaxCard Then MaxCard=CardPower(crd,Xoz)
    Next
    Return MaxCard
End Sub

Private Sub MastExist(hand As List, mast As Int) As Boolean
    Dim MastExists As Boolean
    For i= 0 To hand.Size-1
        Dim crd As Card=hand.Get(i)
        If crd.Mast=mast Then
            MastExists=True
        End If
    Next
    Return MastExists
End Sub

Sub WinnerCard(Cards As List, Xoz As Int) As Int
    Dim MaxCard, MaxCardIndex As Int
    For i= 0 To Cards.Size-1
        Dim crd As Card=Cards.Get(i)
       
        If CardPower(crd,Xoz)> MaxCard Then
            MaxCard=CardPower(crd,Xoz)
            MaxCardIndex=i
        End If
    Next
    Return MaxCardIndex
End Sub

Sub GetTerz(Cards As List) As List
    'Terz 50 100
    Dim Last As Int
   
    Dim lst,lstTotal As List
    lst.Initialize
    lstTotal.Initialize
    Dim Count As Int

    Dim crd As Card
    crd=Cards.Get(0)
    Last=crd.id
   
    For i= 1 To Cards.Size-1
        crd =Cards.Get(i)
        Dim crdID=crd.id

        If lst.Size=0 Then lst.Add(Cards.Get(i-1))
        If Last=crdID-1 Then
            Last=crdID
            Count=Count+1
           
            'If Cards.IndexOf( Cards.Get(i-1))=-1 Then lst.Add(Cards.Get(i-1))
           
            lst.Add(crd)
           
        Else
            If Count>=2 Then
                Dim l As List
               
                l.Initialize
                For g= 0 To lst.Size-1
                    l.Add(lst.Get(g))
                Next
               
                lstTotal.Add(CreateBonusType(l,False))
            End If
           
            If Count>4 Then
                For ri=0 To Abs((Count-5))
                    l.RemoveAt(0)
                Next
               
            End If
           
           
           
            Last=crdID
            Count=0
            lst.Clear
        End If
       
       
       
    Next
   
    If Count>=2 Then
        Dim l As List
               
        l.Initialize
        For g= 0 To lst.Size-1
            l.Add(lst.Get(g))
        Next
               
        lstTotal.Add(CreateBonusType(l,False))
    End If
   
    If Count>4 Then
        For ri=0 To Abs((Count-5))
            l.RemoveAt(0)
        Next
       
       
    End If
   
   
    Last=crdID
    Count=0
    lst.Clear
   
    '''' 4 tuxt

    Dim mID As Map
    mID.Initialize

    For i= 0 To Cards.Size-1
        Dim cr As Card=Cards.Get(i)
        mID.Put(Ceil(cr.id),cr)
    Next

    For iii= 3 To 8
        If mID.ContainsKey(Floor(1 & iii)) And mID.ContainsKey(Floor(2 & iii)) And mID.ContainsKey(Floor(3 & iii)) And mID.ContainsKey(Floor(4 & iii)) Then
            Dim lll As List
            lll.Initialize
            lll.Add(mID.Get(Floor(1 & iii)))
            lll.Add(mID.Get(Floor(2 & iii)))
            lll.Add(mID.Get(Floor(3 & iii)))
            lll.Add(mID.Get(Floor(4 & iii)))
           
            If lstTotal.Size>0 Then
                For i=0 To lstTotal.Size-1
                    If lstTotal.Size=0 Then Exit

                    Dim tmpBonus As Bonus=lstTotal.Get(i)


                    If tmpBonus.BonusType<>4 Then
                        Dim tmpsCardList As List=tmpBonus.BonusCards
                        For ii=0 To tmpsCardList.Size-1
                            Dim tmpCard As Card=tmpsCardList.Get(ii)
                            If tmpCard.Rank=iii Then
                                Log("POVtor")
                                lstTotal.RemoveAt(i)
                                i=i-1
                            End If
                           
                        Next
                    End If
                Next
            End If
           
           
            lstTotal.Add(CreateBonusType(lll,True))
           
           
        End If
    Next
   
    Return lstTotal

End Sub


Private Sub CreateBonusType(cards As List, Tuxt4 As Boolean) As Bonus
    Dim b As Bonus
   
    If Tuxt4 Then
        b.BonusType=4
        b.BonusCards=cards
    Else
   
        If cards.Size=3 Then
            b.BonusType=1
            b.BonusCards=cards
        else if cards.Size=4 Then
            b.BonusType=2
            b.BonusCards=cards
        Else If cards.Size=5 Then
            b.BonusType=3
            b.BonusCards=cards
        End If
    End If
   
    Return b
End Sub

Sub DetectBlotReblot(Cards As List,Xoz As Int) As List
    Dim mID As Map
    mID.Initialize

    For i= 0 To Cards.Size-1
        Dim cr As Card=Cards.Get(i)
        mID.Put(Ceil(cr.id),cr)
    Next
    Dim lst As List
    lst.Initialize
   
    If mID.ContainsKey(Floor(Xoz & 6)) And mID.ContainsKey(Floor(Xoz & 7)) Then
       
        lst.Add(mID.Get(Floor(Xoz & 6)))
        lst.Add(mID.Get(Floor(Xoz & 7)))
       
   
       
    End If
   
   
    Return lst
   
   
End Sub


Sub HandValue(Cards As List,Xoz As Int)
    Dim TotalValue As Int
   
    For i= 0 To Cards.Size-1
        Dim crd As Card=Cards.Get(i)
        If Xoz=5 Then
            Select crd.Rank
                Case 4
                    TotalValue=TotalValue+10
                Case 5
                    TotalValue=TotalValue+2
                Case 6
                    TotalValue=TotalValue+3
                Case 7
                    TotalValue=TotalValue+4
                Case 8
                    TotalValue=TotalValue+19
            End Select
        Else
            If crd.Mast=Xoz Then
                If crd.Rank=3 Then
                    TotalValue=TotalValue+14
                Else If crd.Rank=5 Then
                    TotalValue=TotalValue+20
                Else
                    Select crd.Rank
                        Case 4
                            TotalValue=TotalValue+10
                        Case 6
                            TotalValue=TotalValue+3
                        Case 7
                            TotalValue=TotalValue+4
                        Case 8
                            TotalValue=TotalValue+11
                    End Select
                End If
           
            Else
                Select crd.Rank
                    Case 4
                        TotalValue=TotalValue+10
                    Case 5
                        TotalValue=TotalValue+2
                    Case 6
                        TotalValue=TotalValue+3
                    Case 7
                        TotalValue=TotalValue+4
                    Case 8
                        TotalValue=TotalValue+11
                End Select
            End If
               
        End If
    Next
   
    Return TotalValue
End Sub


Could you try to compile it please. Maybe there is an issue with my b4i

thank u in advance
 

OliverA

Expert
Licensed User
Longtime User
The big issue is this
B4X:
Sub CanPlay (Card As Card,Hand As List,inCards As List, Xoz As Int) As Boolean
You are naming a variable Card the same as the class Card including capitalization. If you change this to
B4X:
Sub CanPlay (aCard As Card,Hand As List,inCards As List, Xoz As Int) As Boolean
and replace your Card variables with aCard (for example, you can name it something else), everything should work.

A couple of warnings that need to be cleaned up
Line 220 you have
B4X:
Dim crdID=crd.id
which gives you a variable declaration missing (warning #5). The system is using String for a declaration. Most likely you meant to write
B4X:
Dim crdID as Int = crd.id
This (line 388)
B4X:
Sub HandValue(Cards As List,Xoz As Int)
is giving you a "no return type given (warning #3), which is fixed with
B4X:
Sub HandValue(Cards As List,Xoz As Int) As Int
 
Upvote 0
Top