Asked by:
Did you know?
General discussion
-
Here are some tips to remember while programming with Small Basic. Feel free to add more as you figure out.
* Double clicking on the compiler errors will take you to the actual error.- Edited by Vijaye Raji Friday, November 14, 2008 10:47 AM suggestions
Friday, November 14, 2008 10:46 AM
All replies
-
Some operations like ImageList.LoadImage or Array.SetValue must be initialized before they can be used. For example:
Array.SetValue(ElementName, 6, "Carbon")
will throw a Null Reference Exception error. You must initialize the variable Elements before using it and it can be initalized to a string or integer.
ElementName = "Periodic Table"
Array.SetValue(ElementName, 6, "Carbon")Friday, November 14, 2008 7:32 PM -
* You can zoom the text in the editor by holding control and using the mouse wheel. You can do the same by holding Control, Shift and hitting + or -.Friday, November 14, 2008 7:53 PM
-
You can resize the Help Pane on the right. Just move the mouse to the left edge of the pane and the cursor will change to indicate it's resizable.Monday, November 17, 2008 6:24 PM
-
You can make the Intellisense Window translucent by holding down the Control key. Useful to see the text underneath.
Tuesday, November 25, 2008 4:46 PM -
The program does not completely close if your Program.End() is in the middle of a loop.
Even the executable closes the Task, but leaves the Process running in Task Manager.
So I have a template that works for me on the projects I have worked on so far.
1) Start off with code that sets up your screens, variables, and Events - code that you don't want executed over and over again.
2) Then setup a main loop (I prefer using While) around the code that does have to process over and over again.
2b) A lot of times there are parts of your code that don't need to be in the main loop. Parts that only need to happen at a specific moment - like when a variable reaches a certain condition or when a key is pressed.
Look for this part of your code and try to make it a regular sub or (especially in the case of key pressing) an Event (see chapter 10 of MSB introduction guide - http://download.microsoft.com/download/9/0/6/90616372-C4BF-4628-BC82-BD709635220D/Introducing Small Basic.pdf).
3) At the end, and outside, of that main loop put your Program.End().
So, something like this:'Setup graphics window for instructions. code code code 'Show instructions code code code 'setup graphics window for use by mainloop code code 'setup Event to read keypress GraphicsWindow.KeyDown = keypress 'Run game until While (EndProgram<>"yes") mainloop() EndWhile Program.End() Sub mainloop code code code code EndSub Sub keypress key = GraphicsWindow.LastKey If (key = "Escape") Then EndProgram = "yes" EndIf EndSub
Another variation puts the main loop inside the While instead if making it a Sub:'Setup graphics window for instructions. code 'Show instructions code 'setup graphics window for use by mainloop code 'setup Event to read keypress GraphicsWindow.KeyDown = keypress 'other settings MainLoopContinue = "Yes" 'Run game until While (MainLoopContinue="Yes") code code code code EndWhile Program.End() Sub keypress key = GraphicsWindow.LastKey If (key = "Escape") Then MainLoopContinue = "No" EndIf EndSub
I hope you find this simple guide useful.
THNX!
drcFriday, December 12, 2008 4:41 AM -
Spell check when posting in these forums:
So that the spell check does not spell check your inserted code, spell check before inserting code.
One better is to spell check by pasting or creating message in an application that has spell check (like Word or Outlook).
Copy from the app into your post and then insert code.
Be careful though because some formatting can be copied over. In my test the font size did copy over, but not the font name.
THNX!
drcFriday, December 12, 2008 4:48 AM -
If you forget the syntax while entering an expression, click back on the Operation name preceding the opening bracket. This will bring the help back up for that command. You can then click where you want to edit and continue.Friday, May 1, 2009 2:47 PM
-
Color (Graphics)
We can use such colors "#FFF" or "#80FFFFFF" in GraphicsWindow.
The first one means "#rgb" and is same as "#FFFFFF".
The second one means "#aarrggbb". "aa" is transparency (alpha blending). But at the point using alpha, GetPixel returns blended color with "Black".
Nonki Takahashi
- Edited by Nonki Takahashi Sunday, December 30, 2012 3:06 PM
Sunday, December 30, 2012 2:21 PM -
Following program shows <> three times. "" <> "" ?
a["a"] = "" b["a"] = "" a["b"] = "b" b["b"] = "b" TextWindow.WriteLine("a[]=" + a[""] + ".") TextWindow.WriteLine("b[]=" + b[""] + ".") If a[""] = b[""] Then TextWindow.WriteLine("a[]=b[]") Else TextWindow.WriteLine("a[]<>b[]") EndIf TextWindow.WriteLine("a[1]=" + a[1] + ".") TextWindow.WriteLine("b[1]=" + b[1] + ".") If a[1] = b[1] Then TextWindow.WriteLine("a[1]=b[1]") Else TextWindow.WriteLine("a[1]<>b[1]") EndIf TextWindow.WriteLine("a[a]=" + a["a"] + ".") TextWindow.WriteLine("b[a]=" + b["a"] + ".") If a["a"] = b["a"] Then TextWindow.WriteLine("a[a]=b[a]") Else TextWindow.WriteLine("a[a]<>b[a]") EndIf
Nonki Takahashi
Wednesday, January 30, 2019 8:05 AM -
Getting a number from inside text
* is the separator inside the variable "texte" between text and number
To remove the spaces from the number add +0
texte= " a b c d * 123 " number = text.getsubtexttoend(texte,text.getindexof(texte,"*")+1) Textwindow.WriteLine("Number With spaces ="+number+"=") number = text.getsubtexttoend(texte,text.getindexof(texte,"*")+1)+0 Textwindow.WriteLine("Number without spaces ="+number+"=")It's useful when placing buttons in the graphics if several are using the same "OFF" statement in the button.
example : If you put as texte in the third "small" button "OFF * 3" you will only see "OFF" as 3 is behind the button but you can easily catch the fieldnumber "3" to make choices in your program
Eddy Abts
- Edited by Eddy Abts Wednesday, January 30, 2019 8:59 AM
Wednesday, January 30, 2019 8:44 AM -
Nonki,
It seems that an empty string is equal an empty string,
an empty array member is equal to an empty string
but an empty array member is not equal to an empty array member ???
Jan [ WhTurner ] The Netherlands
Wednesday, January 30, 2019 10:50 AMAnswerer -
I could use some Small Basic methods/properties in PowerShell script!
Add-Type -Path 'C:\Program Files (x86)\Microsoft\Small Basic\SmallBasicLibrary.dll' $Math = [Microsoft.SmallBasic.Library.Math] $Clock = [Microsoft.SmallBasic.Library.Clock] $Sound = [Microsoft.SmallBasic.Library.Sound] $pi = $Math::Pi $Math::Ceiling($pi) $Math::Floor($pi) $Clock::ElapsedMilliseconds $Sound::PlayBellRing()
Nonki Takahashi
Sunday, May 19, 2019 3:47 PM