running code from PB win10 on PB on linux (ubuntu)

Linux specific forum
Lonely_Star77
User
User
Posts: 26
Joined: Sat Feb 20, 2021 3:39 pm

running code from PB win10 on PB on linux (ubuntu)

Post by Lonely_Star77 »

hello...

I've switched my OS from win 10 to ubuntu 20.04 and I installed purebasic on it just like I had on win 10... during instillation i installed all dependencies except for libgnome2.dev which is obsolete and you cannot install it anymore with apt-get command...

so I started to test my projects that I started on purebasic in win 10 and I see that it doesn't run as expected it gets stuck or buggy...

here is a few examples of code that runs well on purebasic windows but doesn't on Linux...

one a game of Russian roulette code... the game does not excepts input from the console and get stuck - but it worked fine on windows

Code: Select all

;EnableExplicit

#Window_Main = 0

#Screen_Width = 800
#Screen_Height = 600


Global color.i = #White
Global.s name1, name2
Global score1 = 5000, score2 = 5000, ii = 1
Global.b isTurn = #True
Global bank = 2500

InitSprite() 
InitKeyboard()

OpenWindow(#Window_Main, 0, 0, #Screen_Width, #Screen_Height, "TEST", #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#Window_Main), 0, 0, #Screen_Width, #Screen_Height, #True, 0, 0)

Procedure.s inputs()
  Define.s userInput$, userInputChar$
  Repeat
  ExamineKeyboard()       
   
    If KeyboardReleased(#PB_Key_Back)
      userInput$ = Left(userInput$, Len(userInput$) - 1)
    Else
      userInputChar$ = KeyboardInkey()
      If FindString("1234567890 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,.", userInputChar$)
        userInput$ + userInputChar$
      EndIf
    EndIf
    
    ClearScreen(RGB(0, 0, 0))
    
    If StartDrawing(ScreenOutput())
      FrontColor(#White)
      DrawText(100,180, "player " + ii +" enter name please:")
          DrawText(100, 200, userInput$)
        StopDrawing()
      EndIf
      FlipBuffers()
    Until KeyboardReleased(#PB_Key_Return)
    ProcedureReturn userInput$
EndProcedure

Procedure cprint(row.i, text.s)
  DrawText((#Screen_Width - TextWidth(text)) / 2, row , text, color)
EndProcedure

Procedure russian()
  Repeat
    color = #White
  Define k.s
  Dim gun(5)
  Define text1.s = "press key 1 to load gun with one bullet or key 2 for two bollets"
  Define text2.s = ""
  Define text3.s = "Russian Roulette"
  Define text4.s = "--------------------"
  Define shot.i
  Define e 
  Define i
  Define.s t1 = "player 1 " + name1 +"                   " + "player 2 " + name2 
  Define.s t2 =  "Ruballes " + Str(score1) + "                    Ruballes " + Str(score2)
  Define.s t3 = "Bank " + Str(bank)
  Define.s turn
  For i = 0 To 5
    gun(i) = 0
  Next
  
  
  Repeat
    
  ClearScreen(#Black)
;   e = WaitWindowEvent()
  k = KeyboardInkey()
  
  If StartDrawing(ScreenOutput())
    cprint(30, turn)
    cprint(50, text3)
    cprint(70, text4)
    cprint(90, text1)
    cprint(110, t1)
    cprint(130, t2)
    cprint(150, t3)
    cprint(200, text2)
    StopDrawing()
  EndIf
  
  If isTurn = #True
    turn = name1 + " TURN"
  Else
    turn = name2 + " TURN"
  EndIf
  
  If k = "1"
    gun(0) = 1
    text1 = "gun is loaded with one bullet"
    text2 = "press 'r' key to roll the revolver"
  EndIf
  
  If k = "2"
    gun(0) = 1
    gun(3) = 1
    text1 = "gun is loaded with two bullets"
    text2 = "press 'r' key to roll the revolver"
  EndIf
  
  
  If k = "r"
    shot = gun(Random(5,0))
    text1 = "revolver has been rolled"
    text2 = "press space bar to pull the triger or again 'r' to roll the revolver"
  EndIf
  
  If k = Chr(32)
    If shot = 0
      bank + 750
      text2 = "emthy shot"
      text1 = "press 'r' key to roll over revolver"
      If isTurn = #True
        score1 = score1 + 1000 + bank
        score2 = -1000
        isTurn = #False
      Else
        score2 = score2 + 1000 + bank
        score1 = -1000
        isTurn = #True
      EndIf
      
    ElseIf shot = 1
      If isTurn = #True
        score2 = score2 + score1 + bank
        score1 = 0
        bank + 750
        isTurn = #False 
      Else
        score1 = score1 + score2 + bank
        score2 = 0
        bank + 750
        isTurn = #True
      EndIf
      
      text1 = "press key 'enter' to begin again"
      text3 = ""
      text4 = ""
      color = #Red
      text2 = "YOU LOST!"
      ;       e = WaitWindowEvent(2000)
      Delay(2000)
    EndIf
;    ElseIf k = Chr(13)
;       color = #White
;       Break
    

    
  EndIf 
  
 
  
  ExamineKeyboard()
    
  FlipBuffers()
  
  
  Delay(3)
Until k = Chr(13)  
Until shot = 1
color = #White
EndProcedure

Procedure opening()
  Repeat
    Repeat
    Define Event = WindowEvent()
    Select Event
      Case #PB_Event_CloseWindow
        End
    EndSelect
  Until Event = 0
    
  ExamineKeyboard()
  
  If KeyboardPushed(#PB_Key_Space)
    color = #Red
  EndIf
  If StartDrawing(ScreenOutput())
    cprint(50, "Russian Roulette")
    cprint(70, "press key 1 to continue")
    StopDrawing()
  EndIf
  
  FlipBuffers()
  Delay(3)
  Until KeyboardInkey() = "1"
  ClearScreen(RGB(0,0,0))
  color = #White
  name1 = inputs()
  ClearScreen(RGB(0,0,0))
  ii + 1
  name2 = inputs()
  ClearScreen(RGB(0,0,0))
EndProcedure


Procedure main()
Repeat
  Repeat
    Define Event = WindowEvent()
    Select Event
      Case #PB_Event_CloseWindow
        End
    EndSelect
  Until Event = 0
  ClearScreen(#Black)
  If StartDrawing(ScreenOutput())
    cprint(50, "press key 'r' for Russian Roulette or 'ESC' key to exit")
    StopDrawing()
  EndIf
  
  If KeyboardInkey() = "r"
    ClearScreen(RGB(0,0,0))
    russian()
  EndIf
  ExamineKeyboard()
    
    
  FlipBuffers()
  
  Delay(3)  
Until KeyboardPushed(#PB_Key_Escape)
EndProcedure

opening()
main()
second a small test code for pure basic that either crashes or ends right away under Linux

Code: Select all

OpenConsole()

text.s = "hello world!"

Print(text.s)
Input()

CloseConsole()
why does this happen on Linux and how can I code in purebasic under Linux?
Bitblazer
Enthusiast
Enthusiast
Posts: 480
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: running code from PB win10 on PB on linux (ubuntu)

Post by Bitblazer »

Lonely_Star77 wrote: Tue Sep 14, 2021 12:59 pm why does this happen on Linux and how can I code in purebasic under Linux?
PureBasic is outdated regarding linux IMHO. For Ubuntu i am using Ubuntu 18.04 LTS which works fine to me. I heard other people have had good success with MX linux.

You need to use an older linux version, or a linux version with support for old libraries for compatibility reasons.

Just use Ubuntu 18 instead of Ubuntu 20 for now.
Lonely_Star77
User
User
Posts: 26
Joined: Sat Feb 20, 2021 3:39 pm

Re: running code from PB win10 on PB on linux (ubuntu)

Post by Lonely_Star77 »

I would like to ask another question - where in purebasic under Ubuntu Linux are the executables? I compile/run and when I do to the project folder I don't see any executable :O

anyone has any idea how and where can I find the executables of my programs?

PS. found the answer - I need to click "make executable" and it's there and that way it can be tested in console
User avatar
mk-soft
Addict
Addict
Posts: 3191
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: running code from PB win10 on PB on linux (ubuntu)

Post by mk-soft »

Purebasic also works with Ubuntu newer than 18.04.

But unfortunately still with limitations. With Purebasic, the WebKit has not yet been updated. So the WebGadget or the Dialog Library (CreateDialog needs WebKit) does not work.

Otherwise everything works (with some adjustment)
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace
Lonely_Star77
User
User
Posts: 26
Joined: Sat Feb 20, 2021 3:39 pm

Re: running code from PB win10 on PB on linux (ubuntu)

Post by Lonely_Star77 »

it seems to me that the KeyboardInkey() command used to get input on the console in the Russian roulette code does not work :/ what do you propose for me to do?

Code: Select all

Procedure.s inputs()
  Define.s userInput$, userInputChar$
  Repeat
  ExamineKeyboard()       
   
    If KeyboardReleased(#PB_Key_Back)
      userInput$ = Left(userInput$, Len(userInput$) - 1)
    Else
      userInputChar$ = KeyboardInkey()
      If FindString("1234567890 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,.", userInputChar$)
        userInput$ + userInputChar$
      EndIf
    EndIf
    
    ClearScreen(RGB(0, 0, 0))
    
    If StartDrawing(ScreenOutput())
      FrontColor(#White)
      DrawText(100,180, "player " + ii +" enter name please:")
          DrawText(100, 200, userInput$)
        StopDrawing()
      EndIf
      FlipBuffers()
    Until KeyboardReleased(#PB_Key_Return)
    ProcedureReturn userInput$
  
EndProcedure
User avatar
mk-soft
Addict
Addict
Posts: 3191
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: running code from PB win10 on PB on linux (ubuntu)

Post by mk-soft »

Under macOS and Linux with OpenWindowedScreen, the window events must always be queried, otherwise the KeyboardInkey function hangs.
I have written an adaptation of ExamineKeyboardEx for this.

Edit:
Furthermore, there seems to be a problem with the recognition of capital letters under macOS and Linux.
I have written an adaptation of KeyboardInkeyEx for this.

Update

Code: Select all

;EnableExplicit

#Window_Main = 0

#Screen_Width = 800
#Screen_Height = 600


Global color.i = #White
Global.s name1, name2
Global score1 = 5000, score2 = 5000, ii = 1
Global.b isTurn = #True
Global bank = 2500

InitSprite() 
InitKeyboard()

OpenWindow(#Window_Main, 0, 0, #Screen_Width, #Screen_Height, "TEST", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(#Window_Main), 0, 0, #Screen_Width, #Screen_Height, #True, 0, 0)

Procedure ExamineKeyboardEx()
  Repeat
    Select WindowEvent()
      Case 0
        Break
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
  ExamineKeyboard()       
EndProcedure

Procedure.s KeyboardInkeyEx()
  Protected key.s
  key = KeyboardInkey()
  If KeyboardPushed(#PB_Key_LeftShift) Or KeyboardPushed(#PB_Key_RightShift)
    key = UCase(key)
  EndIf
  ProcedureReturn key
EndProcedure

Procedure.s inputs()
  Define.s userInput$, userInputChar$
  Repeat
    ExamineKeyboardEx()       
    If KeyboardReleased(#PB_Key_Back)
      userInput$ = Left(userInput$, Len(userInput$) - 1)
    Else
      userInputChar$ = KeyboardInkeyEx()
      If FindString("1234567890 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,.", userInputChar$)
        userInput$ + userInputChar$
      EndIf
    EndIf
    
    ClearScreen(RGB(0, 0, 0))
    
    If StartDrawing(ScreenOutput())
      FrontColor(#White)
      DrawText(100,180, "player " + ii +" enter name please:")
      DrawText(100, 200, userInput$)
      StopDrawing()
    EndIf
    FlipBuffers()
  Until KeyboardReleased(#PB_Key_Return)
  ProcedureReturn userInput$
EndProcedure

Procedure cprint(row.i, text.s)
  DrawText((#Screen_Width - TextWidth(text)) / 2, row , text, color)
EndProcedure

Procedure russian()
  Repeat
    color = #White
    Define k.s
    Dim gun(5)
    Define text1.s = "press key 1 to load gun with one bullet or key 2 for two bollets"
    Define text2.s = ""
    Define text3.s = "Russian Roulette"
    Define text4.s = "--------------------"
    Define shot.i
    Define e 
    Define i
    Define.s t1 = "player 1 " + name1 +"                   " + "player 2 " + name2 
    Define.s t2 =  "Ruballes " + Str(score1) + "                    Ruballes " + Str(score2)
    Define.s t3 = "Bank " + Str(bank)
    Define.s turn
    For i = 0 To 5
      gun(i) = 0
    Next
    
    
    Repeat
      
      ClearScreen(#Black)
      ;   e = WaitWindowEvent()
      k = KeyboardInkey()
      
      If StartDrawing(ScreenOutput())
        cprint(30, turn)
        cprint(50, text3)
        cprint(70, text4)
        cprint(90, text1)
        cprint(110, t1)
        cprint(130, t2)
        cprint(150, t3)
        cprint(200, text2)
        StopDrawing()
      EndIf
      
      If isTurn = #True
        turn = name1 + " TURN"
      Else
        turn = name2 + " TURN"
      EndIf
      
      If k = "1"
        gun(0) = 1
        text1 = "gun is loaded with one bullet"
        text2 = "press 'r' key to roll the revolver"
      EndIf
      
      If k = "2"
        gun(0) = 1
        gun(3) = 1
        text1 = "gun is loaded with two bullets"
        text2 = "press 'r' key to roll the revolver"
      EndIf
      
      
      If k = "r"
        shot = gun(Random(5,0))
        text1 = "revolver has been rolled"
        text2 = "press space bar to pull the triger or again 'r' to roll the revolver"
      EndIf
      
      If k = Chr(32)
        If shot = 0
          bank + 750
          text2 = "emthy shot"
          text1 = "press 'r' key to roll over revolver"
          If isTurn = #True
            score1 = score1 + 1000 + bank
            score2 = -1000
            isTurn = #False
          Else
            score2 = score2 + 1000 + bank
            score1 = -1000
            isTurn = #True
          EndIf
          
        ElseIf shot = 1
          If isTurn = #True
            score2 = score2 + score1 + bank
            score1 = 0
            bank + 750
            isTurn = #False 
          Else
            score1 = score1 + score2 + bank
            score2 = 0
            bank + 750
            isTurn = #True
          EndIf
          
          text1 = "press key 'enter' to begin again"
          text3 = ""
          text4 = ""
          color = #Red
          text2 = "YOU LOST!"
          ;       e = WaitWindowEvent(2000)
          Delay(2000)
        EndIf
        ;    ElseIf k = Chr(13)
        ;       color = #White
        ;       Break
        
        
        
      EndIf 
      
      
      
      ExamineKeyboardEx()
      
      FlipBuffers()
      
      
      Delay(3)
    Until k = Chr(13)  
  Until shot = 1
  color = #White
EndProcedure

Procedure opening()
  Repeat
    ExamineKeyboardEx()
    
    If KeyboardPushed(#PB_Key_Space)
      color = #Red
    EndIf
    If StartDrawing(ScreenOutput())
      cprint(50, "Russian Roulette")
      cprint(70, "press key 1 to continue")
      StopDrawing()
    EndIf
    
    FlipBuffers()
    Delay(3)
  Until KeyboardInkey() = "1"
  ClearScreen(RGB(0,0,0))
  color = #White
  name1 = inputs()
  ClearScreen(RGB(0,0,0))
  ii + 1
  name2 = inputs()
  ClearScreen(RGB(0,0,0))
EndProcedure


Procedure main()
  Repeat
    ClearScreen(#Black)
    If StartDrawing(ScreenOutput())
      cprint(50, "press key 'r' for Russian Roulette or 'ESC' key to exit")
      StopDrawing()
    EndIf
    
    If KeyboardInkey() = "r"
      ClearScreen(RGB(0,0,0))
      russian()
    EndIf
    ExamineKeyboardEx()
    
    FlipBuffers()
    
    Delay(3)  
  Until KeyboardPushed(#PB_Key_Escape)
EndProcedure

opening()
main()
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace
Post Reply