getJibba - Extensions

X-Extenion Set

last update 23-Feb-2016

Is basically a solution of things I would like Small Basic to be able to do. Complete documentation is on this page.


XApp

'BROWSER TYPE PROGRAM
path = Program.Directory + "\NewProcess.exe"
start = Controls.AddButton("NewProcess", 5, 5)
getAll = Controls.AddButton("Get All", 5, 35)
kill = Controls.AddButton("Kill", 5, 65)
Controls.ButtonClicked = OnButtonClicked

While 0=0
  If lastButtonClicked = "NewProcess" Then
    'process = XApp.StartProcess(path) 'OR
    process = XApp.StartWithStartInfo(path, "maximized", "userName")
  ElseIf lastButtonClicked = "Get All" Then
    all = XApp.GetAllProcesses(XApp.MachineName)
    TextWindow.WriteLine(all)
  ElseIf lastButtonClicked = "Kill" Then
      XApp.Kill(process)
  EndIf
  lastButtonClicked = ""

Program.Delay(15)
EndWhile

Sub OnButtonClicked
  lastButtonClicked = Controls.GetButtonCaption(Controls.LastClickedButton)
EndSub

XApp provides ways to start & kill other programs as new processes.
The window style of the new process can be specified.
Arguments can also be passed to the new process.

Class members are:

From 1 SB program to another program you can:

  1. StartProcess: process = XApp.StartProcess(path)
    • Start a program where path is the path of the exe program to start.
    • Returns the name of the process.
  2. KillProcess: XApp.Kill(process)
    • Immediately ends the program.
  3. StartWithStartInfo: process = XApp.StartWithStartInfo(path, "maximized", "userName")
    • Starts a program with the window style you specify. "" starts as normal.
    • You can also pass info (args) to the new program. "" sends nothing.
    • Multiple Args can be sent as a delimited string, like "userName,rank,accountNumber".
    • These args can picked up by a new SB program by using Program.GetArgument(1).
  4. GetAllProcesses: all = XApp.GetAllProcesses(XApp.MachineName)
    • Returns a list of ALL the processes currently running on the specified machine.
  5. XApp.MachineName:
    • Gets the machine name of the local computer

'OPENS THIS PROGRAM
getArgs = Program.GetArgument(1)
GraphicsWindow.Title = getArgs

XDialogue

GraphicsWindow.Show()
retOne = XDialogue.YesNo("Program Name","Save File?")
retTwo = XDialogue.Password("User Name", "Re-enter password")

TextWindow.WriteLine(retOne)
TextWindow.WriteLine(retTwo)

Provides a "Yes No" dialogue box and a secure password dialogue box.


XEnvironment

NL = XEnvironment.NewLine
userName = XEnvironment.UserName
TextWindow.WriteLine("Hello" + NL + userName)
Provides some handy Environment properties.

XLeadersBoard

'How to use XLeadersBoard in a game loop

Initialise()

While "True"
  If timeToUpdate Then
    'Uses gameName, player & the dateTime value returned during Initialise to
    'update the correct record for this session
    XLeadersBoard.UpdateRecord(gameName, player, dateTime, 10, 2000)
  EndIf

  If timeToShowLeadersBoard Then
    'Gets the top 10 Scores in CSV format. You specify the limit, could be top 50
    XLeadersBoard.GetLeaders(gameName, 10)
  EndIf

EndWhile

Sub Initialise
  gameName = "MyGameByMe"  'A unique name with no Spaces
  XLeadersBoard.CreateTable(gameName)

  player = "Freddie"
  'Add record to the table - this record will be used for the current session.
  'Store the dateTime value as this is used to ID the record added for session updates.
  dateTime = XLeadersBoard.AddRecord(gameName, player, 0, 0)
EndSub

'==========================================================
'Also there's GetAllRecords
'==========================================================
'This will return ALL the records, sorted from best to worst for the game specified
XLeadersBoard.GetAllRecords(gameName)

The LeadersBoard is 1 large SQLite database that is hosted on this site.

Class members are:

To use you:

  1. CreateTable: CreateTable("GameNameByJibba")
    • Create a unique table for the game by using the games name and the programmers name.
    • This is done once ussually when initialising the program.
    • Does nothing if the table already exists.
  2. AddRecord: dateTimeRef = AddRecord("GameNameByJibba", "PlayersName", 0, 0)
    • Add a record for the current game.
    • A time stamp will be returned and added to this record so it can be uniquely referenced.
  3. UpdateRecord: UpdateRecord("GameNameByJibba", "PlayersName", dateTimeRef, 150, 1200)
    • By using the dateTimeRef you can update the added record throughout the game with scores and time taken to reach that score.
  4. GetLeaders: GetLeaders("GameNameByJibba", 10)
    • Returns a sorted CSV table of the highest scores you specify the amount. In this case the top 10.
    • The table is sorted by score, time and player in DESC, ASC and ASC order repectively.
  5. GetAllRecords: GetAllRecords("GameNameByJibba")
    • This will return ALL the records for the game in the order they were added.
    • Use this to see a complete history of the game.


XMath

gcd = XMath.GreatestCommonDivisor(102352, 53212)
TextWindow.WriteLine(gcd)

primeFactors = XMath.PrimeFactors(1238)
TextWindow.WriteLine(primeFactors)

primeNumbers = XMath.PrimeNumbers(1000000, 1000090)
TextWindow.WriteLine(primeNumbers)
Currently provides some prime number functions especially for very large numbers.