Ok now that I have some time to code and play around, I'm trying to get back into it.
Thus I find my self in a situation that I'm not sure what is going on. I have an array with 16 elements (0-15) and I have a RND statement that I think is supposed to give me results of 0-15(RND * 16) But every so often I am receiving a Subscript out of range error.
am I just goofing or is something else going on? What am I forgetting here?
Line 41 is listed as the error line, which is the RND * 16 line.
I've attached the needed files to run it , if your curious just what it does.
Steve, I would be interested in your thoughts on how it is setup and what it puts out.
Code: (Select All)
TYPE Player_Stat
Name AS STRING * 16
Title AS STRING * 24
Strength AS _BYTE
Dexterity AS _BYTE
Constitution AS _BYTE
Intelligence AS _BYTE
Wisdom AS _BYTE
Charisma AS _BYTE
HP AS _BYTE
MP AS _BYTE
Max_HP AS _BYTE
Max_MP AS _BYTE
Xp AS LONG
Nxp AS LONG
Level AS _BYTE
Age AS _UNSIGNED _BYTE
Race AS _BYTE
END TYPE
SCREEN _NEWIMAGE(800, 600, 32)
RANDOMIZE TIMER
DIM SHARED Layer(8) AS LONG, Font(4) AS LONG, P AS Player_Stat
DIM SHARED Titles(15) AS STRING, Race(4) AS STRING
DATA "Novice","Aspirant","Battler","Fighter","Adept","Chevalier","Veteran","Warrior","Swordman","Hero","Soldier","Myrmidon","Champion","Superhero","Paladin","Lord"
DATA "Mystery","Human","Zombie","Dwarf","Elves"
FOR i% = 0 TO 15: READ Titles(i%): NEXT
FOR i% = 0 TO 4: READ Race(i%): NEXT
Layer(0) = _DISPLAY
Layer(1) = _COPYIMAGE(Layer(0))
Layer(2) = _LOADIMAGE("8x6CharSheet.bmp", 32)
Layer(3) = _LOADIMAGE("portraits2.jpg", 32)
Font(1) = _LOADFONT("ComicRunes.otf", 40, "monospace")
Font(2) = _LOADFONT("ComicRunes.otf", 24, "monospace")
Font(3) = _LOADFONT("DwarvenStonecraftCyr.otf", 24, "monospace")
_FONT Font(1)
_PRINTMODE _KEEPBACKGROUND
_SCREENMOVE 10, 10
COLOR _RGB32(0)
P.Name = "Ryo Seaba"
P.Title = Titles(RND * 16)
Stat_Maker
Enhancements
#392 - Allow single quoted strings in $VERSIONINFO. - @a740g
#399 - The IDE waits for release of F5 key before running the program to avoid start of multiple copies of the program. - @SteveMcNeill
#401 - Add Support for optional paramter for an image handle to CLS. - @SteveMcNeill
#404 - Increased the maximum number of possible SUBs/FUNCTIONs in a program from 1000 to 25000. - @SteveMcNeill
#414, #415 - Implemented $EMBED metacommand and _EMBEDDED$ function. - @RhoSigma-QB64
Can be used to embed any files (images, sounds, fonts and other assets) into the compiled executable and recall it in the program when needed.
Read the respective Wiki pages: $EMBED and EMBEDDED$
Bug Fixes
#389 - Internal fixes to use correct math functions from std:: namespace. - @a740g
#391 - Fixed no sound issue on maccOS discussed in this forum posts. - @a740g
#397, #398 - Fixed several CONST issues. - @SteveMcNeill
#405 - Fixed checking for invalid domains in _ARCSEC and _ARCCSC as per the forum posts
#407, #410 - Change IDE save method for better speed on big source files. - @SteveMcNeill
#412 - Avoid segfault on bogus SVG data pretending to be valid SVG text. - @a740g
Full Changelog: v3.9.1...v3.10.0
I just ran across something that I did not either realize or should not be happening.
When an image is freed using _FREEIMAGE the associated variable is not reset to zero but instead retains the negative value of the image assigned. Is this normal behavior?
The code above shows that when images are freed the associated variable retains the image value. I would expect the variable to be reset to zero along with the image being removed from memory.
Another demo program showing how to draw SVGs and load them via memory buffer to use SVG as an alternative drawing method.
SVG's can draw polygons with a simple path definition that is mostly string of numbers.
this string "<path stroke ='#FFFFFF' fill='#FF0000' stroke-width='3' d ='M 200 200 700 200 700 400 200 400 200 200'/>" would draw a red rectangle with a 3 pixel wide white border if embedded in complete SVG string. The polygon is simply defined as a series of points. The only variation in this series of points is the use of M which tells any program drawing the path to move to the following point instead of drawing to the point.
In this example the subroutione svgpoly$ will take a randomly defined polygons and convert them into an SVGpath description held in a string. The path descriptions will be inserted into a complete SVG definition and loaded into a memory buffer and displayed.
Code: (Select All)
'SVG polygon drawing example
'drawing polygons with paths
'a QB64 example by James D. Jarvis
'works with QB64-PE version 3.9.0 and later
'
'this demonstrates how to use subroutines to build a multiple polygon definitions and combine them into a memory buffer that is
'loaded and displayed
Screen _NewImage(800, 500, 32)
Randomize Timer
Dim si As _Unsigned Long 'the SVG image buffer, it's an image handle like any other
Do
Cls , _RGB32(Int(Rnd * 256), Int(Rnd * 256), Int(Rnd * 256)) 'clear the screen and fill it with a random color
ss$ = "" 'the the SVG string
'build the polygons for the demo
np = Int(6 + Int(Rnd * 100))
If Rnd * 100 < 3 Then np = np * 20
For p = 1 To np
ss$ = ss$ + svgpoly$(Int(25 + Rnd * (_Width - 50)), Int(25 + Rnd * (_Height - 50)), Int(10 + Rnd * 100), Int(10 + Rnd * 120), (Int(Rnd * 90)), Int(1 + Rnd * 10), _RGB32(Int(Rnd * 256), Int(Rnd * 256), Int(Rnd * 256)), _RGB32(Int(Rnd * 256), Int(Rnd * 256), Int(Rnd * 256)))
Next p
'take the polygon defintions and compine them with the rest of the SVG string
ss$ = "<svg width='" + _Trim$(Str$(_Width)) + "' height='" + _Trim$(Str$(_Height)) + "'>" + ss$ + " </svg>" 'putting all those polygons inside an SVG as large as the window
si = _LoadImage(ss$, 32, "memory") 'load the svg described in ss$ into memory
_PutImage (0, 0), si 'put the svg on the screen, using 0,0 because the source SVG is as large as the window
tt$ = Str$(p) + " polygons": _Title tt$ 'put the polygon count in the window title
Sleep
_FreeImage si 'free the image so we can load a new one without wasting memory or if we are exiting the program
Loop Until InKey$ = Chr$(27)
'_CLIPBOARD$ = ss$ 'windows users can uncomment the commad on the left to dump the last sbg drawn to their clipboard.
Function svgpoly$ (cx, cy, rr, shapedeg, turn, ww, bklr As _Unsigned Long, fklr As _Unsigned Long)
'filled rotated polygon returned as a string portion of an svg string buffer
'cx,cy are center of polygon
'rr oios radius of polygon
'shapedeg is the angle forming the basis of the polygon , if it doesn't divide into 360 evenly an irregular polygon will be created
'turn will be the angle the whole polygon is turned off of 0 degree
'ww is the width fo the border border stroke of the polygon
'output returned from theis function will be astring holding an SVG path describing a polygon.
'
'define the path that will form the polygon and fill the border and fill colors
i$ = i$ + "<path stroke ='" + packcolorN$(bklr) + "' fill='" + packcolorN$(fklr) + "' "
'add the stroke width
i$ = i$ + " stroke-width='" + _Trim$(Str$(ww)) + "' "
'find the 1st point in the polygon
x = rr * Sin(0.01745329 * turn)
y = rr * Cos(0.01745329 * turn)
'tell the svg to draw the path by moving to the first point of the polygon
i$ = i$ + "d ='M"
i$ = i$ + Str$(cx + x) + Str$(cy + y) + Str$(cx + x) + Str$(cy + y)
'find the perimter of the polygon
For deg = turn To turn + 360 Step shapedeg
x2 = rr * Sin(0.01745329 * deg)
y2 = rr * Cos(0.01745329 * deg)
'record the consecutive points of the polygon that will be drawn to form the path that defines the polygon perimeter
i$ = i$ + Str$(cx + x2) + Str$(cy + y2)
Next
'close the polyon by drawing to the first point
i$ = i$ + Str$(cx + x) + Str$(cy + y)
i$ = i$ + "'/>" 'end the path definition of the polygon
svgpoly$ = i$ 'return this path holding a polygon definiton to the SVG to be drawn
End Function
Function packcolorN$ (klr As _Unsigned Long)
'convert an unsigned long color value into a hexidecimal # that will be used in an SVG
Dim As _Unsigned Long rk, gk, bk
'get the color channels of the unsinged long color
rk = _Red32(klr)
gk = _Green32(klr)
bk = _Blue32(klr)
'convert those channel values into hexidecimal
If rk < 16 Then
r$ = "0" + Hex$(rk) 'put in a padded hexidcimal value
Else
r$ = Hex$(rk) 'put in a 2 digit hexidecimal value
End If
If gk < 16 Then
g$ = "0" + Hex$(gk) 'put in a padded hexidcimal value
Else
g$ = Hex$(gk) 'put in a 2 digit hexidecimal value
End If
If bk < 16 Then
b$ = "0" + Hex$(bk) 'put in a padded hexidcimal value
Else
b$ = Hex$(bk) 'put in a 2 digit hexidecimal value
End If
packcolorN$ = "#" + r$ + g$ + b$
End Function
As usual, it's Christmas time once again, and those of you who have been members of the QB64 community for a while, you know what that means!! It's the time of year when Santa Steve shows up and offers a hard drive full of goodies for one and all!
Now most years, Santa Steve just downloads and archives the QB64 wiki, and makes them available for one and all so they can have full access to the year's newest wiki information -- but this year, Santa Steve has went above and beyond even that!! This year, Santa Steve is hosting and offering the whole QB64-PE FORUMS as well as the QB64-PE WIKI for everyone to enjoy!!
(Note that the small attachment is JUST the Wiki, while the 2nd, larger attachment is both the Wiki and the Forums.)
If you want it, there's no reason why you can't grab a copy of the QB64-PE Archives for 2023! It's free! It's available for one and all!
If you're in a country or area that absolutely can't download the archive (perhaps due to bandwidth issues or some other such thing), then post here! It's Christmas time, for goodness sake! Somebody can burn off a copy of the archive to a DVD and snail mail it to you, if that's absolutely necessary!
Does anyone have any ideas on how a QB64PE program can disable the print screen function when running?
Ideally I would like to be able to hook the keyboard's PRINT SCREEN key to intercept keypresses while at the same time disabling the operating system from grabbing a screen shot. However, disabling the operating system's ability to perform screen shots while the program is running would be just as useful.
Quote: This booklet contains a collection of sorting and searching algorithms.
While many books on data structures describe sorting and searching algorithms,
most assume a background in calculus and probability theory. Although a formal
presentation and proof of asymptotic behavior is important, a more intuitive
explanation is often possible.
The way each algorithm works is described in easy-to-understand terms. It
is assumed that you have the knowledge equivalent to an introductory course in C
or Pascal. In particular, you should be familiar with arrays and have a basic
understanding of pointers. The material is presented in an orderly fashion,
beginning with easy concepts and progressing to more complex ideas. Even though
this collection is intended for beginners, more advanced users may benefit from
some of the insights offered. In particular, the sections on hash tables and skip
lists should prove interesting.
I have run into a situation where the IDE is showing an error in my use of a Select Case. I have 4 cases the last one being Case "Extreme". Attached is a clip of the code and warning box. Normally this would mean I have missed an End IF or a Next but at the moment I can't seem to find it.. I'll keep looking but my question here is that mysterious "7" which you see in the warning box which highlights Case "Extreme" , 7 .... there is no 7 on that case line. Any idea what that 7 means and if it may be pointing me to where I need to address the problem?
The BIMDAS rules (universal priority rules for math) sets priority for math operations as Brackets, Indices, Multiplication, Division, Addition, Subtraction.
Within the BIMDAS rules, the expression 5+4*3^2-1/2 becomes (3^2)*4/2+5-1 B I M D A S and the result is 22.
With the re-arrangement, Phoenix returns 22, as expected.
but when entered as 5 + 4 * 3 ^ 2 - 1 / 2, it returns 40.5
Does this mean we must apply the BIMDAS rules manually, or am I missing something? Print "Am I missing something here?"