Welcome, Guest |
You have to register before you can post on our site.
|
Forum Statistics |
» Members: 483
» Latest member: aplus
» Forum threads: 2,795
» Forum posts: 26,349
Full Statistics
|
|
|
Is this STRING bug? - Not. My fail! |
Posted by: Petr - 03-28-2024, 07:21 PM - Forum: Help Me!
- Replies (3)
|
|
Code: (Select All)
$NoPrefix
ReDim Shared Room(1000, 1000) As Integer
Dim Shared ProjectName As String * 12 'try AS STRING * 5 ----> Out of memory bug occur here
ProjectName$ = "Test"
Type Room1D
As Integer Sx, Ex, Sy, Ey, Typ, Draw, C, Width, Depth
As String * 10 Name
End Type
ReDim Shared Room1(0) As Room1D
Room1(0).Sx = 20
Room1(0).Ex = 100
Room1(0).Sy = 20
Room1(0).Ey = 1000
Room1(0).Typ = 0
Room1(0).Draw = -1
Room1(0).C = 1
Room1(0).Width = 20
Room1(0).Depth = 20
ReDim _Preserve Room1(1) As Room1D
Print "Saving:"
Dim As Integer LB1, LB2, UB1, UB2
LB1 = LBound(Room, 1)
LB2 = LBound(Room, 2)
UB1 = UBound(Room, 1)
UB2 = UBound(Room, 2)
Print "Lbound nr 1 - Room :", LB1
Print "Lbound nr 2 - Room: ", LB2
Print "Ubound nr 1 - Room:", UB1
Print "Ubound nr 2 - Room:", UB2
Print "Project name string: ", ProjectName$ 'shared string variable
LB1 = LBound(Room1)
UB1 = UBound(Room1)
Print "Lbound - Room1:", LB1
Print "Ubound - Room1", UB1
If FileExists("test") Then Kill "test"
SaveRoom "test"
LoadRoom "test"
Print "---------------------------"
Print "Loaded is:"
LB1 = LBound(Room, 1)
LB2 = LBound(Room, 2)
UB1 = UBound(Room, 1)
UB2 = UBound(Room, 2)
Print "Lbound nr 1 - Room :", LB1
Print "Lbound nr 2 - Room: ", LB2
Print "Ubound nr 1 - Room:", UB1
Print "Ubound nr 2 - Room:", UB2
Print "Project name string: ", ProjectName$
LB1 = LBound(Room1)
UB1 = UBound(Room1)
Print "Lbound - Room1:", LB1
Print "Ubound - Room1", UB1
Sub LoadRoom (Project$)
ff = FreeFile
If _FileExists(Project$) Then
Open Project$ For Binary As #ff
Dim As Integer LB1, LB2, UB1, UB2
ReDim ProjectName As String * 16
Get #ff, , LB1
Get #ff, , LB2
Get #ff, , UB1
Get #ff, , UB2
ReDim Room(LB1 To UB1, LB2 To UB2) As Integer
Get #ff, , Room()
Get #ff, , ProjectName$ 'try comment this in both (loadroom and saveroom) and try again
Get #ff, , LB1
Get #ff, , UB1
ReDim Room1(LB1 To UB1) As Room1D
Get #ff, , Room1()
Else
errStat = _MessageBox("Error!", "File " + Project$ + " not exists.", "ok", "error", 1&)
End If
End Sub
Sub SaveRoom (Project$)
ff = FreeFile
If _FileExists(Project$) Then
errStat = _MessageBox("Error!", "File " + Project$ + " already exists. Overwrite?", "yesnocancel", "error", 2&)
If errStat = 1 Then GoTo OverWrite
Else
OverWrite:
ff = FreeFile
Open Project$ For Binary As #ff
Dim As Integer LB1, LB2, UB1, UB2
LB1 = LBound(Room, 1)
LB2 = LBound(Room, 2)
UB1 = UBound(Room, 1)
UB2 = UBound(Room, 2)
Put #ff, , LB1
Put #ff, , LB2
Put #ff, , UB1
Put #ff, , UB2
Put #ff, , Room()
Put #ff, , ProjectName$ 'try comment this in both (loadroom and saveroom) and try again
LB1 = LBound(Room1)
UB1 = UBound(Room1)
Put #ff, , LB1
Put #ff, , UB1
Put #ff, , Room1()
End If
End Sub
I discovered unexpected behavior in the source code provided. I save the contents of the fields with information about the size of the fields to a file and then read that information. Focus on the Room1 array size read (the last two entries). Then try changing above in the declaration DIM SHARED ProjectName AS STRING *12 to a different size *. When I entered *5, an error occurred - out of memory. When I changed it differently, the output of the read values LBOUND and UBOUND, which are written after this string in the test file, also changed.
If I disable writing and then reading ProjectName$ variable in LoadRoom and SaveRoom and then load, everything works fine.
Tested in QB64Pe x32 v3.12
|
|
|
Courage, Luck, or Strategy |
Posted by: SMcNeill - 03-28-2024, 05:46 AM - Forum: SMcNeill
- No Replies
|
|
How much money can you win??
Code: (Select All)
_Title "Courage, Luck, or Strategy?"
Screen _NewImage(1280, 720, 32)
$Color:32
Randomize Timer
Dim Shared As Long font(12 To 64), LockLevel, Chances, Betlevel
Dim Shared cash(11) As String
cash(0) = "$0": cash(1) = "$1,000": cash(2) = "$2,000"
cash(3) = "$4,000": cash(4) = "$8,000": cash(5) = "$16K"
cash(6) = "$32K": cash(7) = "$64K": cash(8) = "$128K"
cash(9) = "$256K": cash(10) = "$512K": cash(11) = "$1000000"
For i = 12 To 64
font(i) = _LoadFont("courbd.ttf", i, "monospace")
Next
LockLevel = 0 'but you could lose it all! Arrrghh!
Chances = 3 'but you have 3 chances to turn your fate around!
Betlevel = 1 'and you haven't made any bets with your winnings so far!
Do
Cls , 0
DrawProgress
ProcessInput
If Chances < 0 Then Quit
_Display
_Limit 30
Loop
Sub Quit
Cls
Color White, 0
Print "You have won:"; cash(Betlevel)
End Sub
Sub ProcessInput
Static OldMB
While _MouseInput: Wend
mx = _MouseX: my = _MouseY
mb = _MouseButton(1)
If mb And Not OldMB Then
If my >= 500 And my <= 600 Then 'down in the control column
Select Case mx
Case 150 To 350 'bet
r = Int(Rnd * 100) + 1
If r < 50 Then
Betlevel = Betlevel + 1
Else
Betlevel = LockLevel
LockLevel = 0
Chances = Chances - 1
End If
Case 400 To 600 'lock
If Chances > 0 And Betlevel <> LockLevel Then
LockLevel = Betlevel
Chances = Chances - 1
End If
Case 650 To 850 'quit
Chances = -1
End Select
End If
End If
OldMB = mb
End Sub
Sub DrawProgress
_Font font(32)
Color Black, 0
For y = 0 To 1
For i = 0 To 5
xc = i * 200 + 100: yc = 120 + 240 * y
If y * 6 + i <= LockLevel Then
CircleFill xc, yc, 90, Gold
ElseIf y * 6 + i <= Betlevel Then
CircleFill xc, yc, 90, Green
Else
CircleFill xc, yc, 90, Red
End If
_UPrintString (xc - _UPrintWidth(cash(y * 6 + i)) / 2, yc - _UFontHeight / 2), cash(y * 6 + i)
Next
Next
Line (150, 500)-Step(200, 100), Red, BF
_UPrintString (220, 534), "Bet"
Line (400, 500)-Step(200, 100), Gold, BF
_PrintString (420, 534), "Lock:" + Str$(Chances)
Line (650, 500)-Step(200, 100), Green, BF
_PrintString (710, 534), "Quit"
End Sub
Sub CircleFill (CX As Integer, CY As Integer, R As Integer, C As _Unsigned Long)
' CX = center x coordinate
' CY = center y coordinate
' R = radius
' C = fill color
Dim Radius As Integer, RadiusError As Integer
Dim X As Integer, Y As Integer
Radius = Abs(R)
RadiusError = -Radius
X = Radius
Y = 0
If Radius = 0 Then PSet (CX, CY), C: Exit Sub
Line (CX - X, CY)-(CX + X, CY), C, BF
While X > Y
RadiusError = RadiusError + Y * 2 + 1
If RadiusError >= 0 Then
If X <> Y + 1 Then
Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
End If
X = X - 1
RadiusError = RadiusError - X * 2
End If
Y = Y + 1
Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
Wend
End Sub
Sub Pause (time As _Float, exclude_code As Long)
'exclude_code is the binary value of things we don't want to allow to break Pause
'1 = Window lost focus
'2= No Mouse breaking pause
'4 - No Keyboard breaking pause
'8 - No Keyup events break pause
'16 - No modifier keys breaking pause (Shift/Ctrl/Alt)
t# = Timer + time
Do
If time <> 0 And Timer > t# Then Exit Do
If k <> 0 Then Exit Do
_Limit 10 'we're a pause. We don't need to do a bunch of crap per second.
If (exclude_code And 1) Then 'don't unpause until window has focus or time has ran out
If _WindowHasFocus = 0 Then _Continue
End If
If (exclude_code And 2) = 0 Then 'mouse clicks break pause
While _MouseInput: Wend
If _MouseButton(1) Or _MouseButton(2) Then Exit Do
End If
If (exclude_code And 4) = 0 Then 'we allow keyboard input (of some sort) to break pause
k = _KeyHit
If (exclude_code And 8) Then If k < 0 Then k = 0 'but we don't allow keyup events to do it
If (exclude_code And 16) Then 'here we don't allow modifier keys to do it
Select Case k
Case 100304, 100303, -100304, -100303 'shift up/down
k = 0
Case 100306, 100305, -100306, -100305 'ctrl up/down
k = 0
Case 100308, 100307, -100308, -100307 'alt up/down
k = 0
End Select
End If
End If
Loop
End Sub
A little gambling game here, where you have a few basic options to try and sort out how to get the most reward out of your luck.
For starters, you start with $1000, which is yours to keep -- if you walk away right at this moment!
OR....
You can gamble on it, with 50/50 odds on whether you increase your pot, or not -- up to a maximum of $100000!
To add a strategy element to this little game, you can LOCK in your winnings, up to 3 times! But the problem here is that once you bet and lose, that lock disappears, meaning you'll have to use another lock again if you want to keep your winnings safe -- and you only have a total of 3 locks in the game.
You can play as long as you have locks left, and money to bet. Each time you bet and lose, you lose one of your locks, so you're only allowed a few failures in each game!
Now the question is: How much money can you win? How good is your luck, courage, and strategy??
(For the record, I suck at this type thing. My highest winning so far has been $16,000 -- I can't even get down to the second line with my luck! And most times, I end up winning $0.)
|
|
|
Smart Pause |
Posted by: SMcNeill - 03-28-2024, 02:45 AM - Forum: SMcNeill
- Replies (1)
|
|
Code: (Select All)
Print "A 10 second pause, with no break method"
Pause 10, -1 'this has to run for 10 seconds, and no input/process from the user will change that
Print "A 10 second pause, with ONLY mouse break early"
Pause 10, 1 + 4
Print "A pause, with no time limit, and ONLY mouse break"
Pause 0, 1 + 4
Print "A pause, no time limit, with only active window keyboard input break"
Pause 0, 1 + 2
Print "A 10 second pause, which any keypress or mouse click can break"
Pause 10, 0
Sub Pause (time As _Float, exclude_code As Long)
'exclude_code is the binary value of things we don't want to allow to break Pause
'1 = Window lost focus
'2= No Mouse breaking pause
'4 - No Keyboard breaking pause
'8 - No Keyup events break pause
'16 - No modifier keys breaking pause (Shift/Ctrl/Alt)
t# = Timer + time
Do
_Limit 10 'we're a pause. We don't need to do a bunch of crap per second.
If (exclude_code And 1) Then 'don't unpause until window has focus or time has ran out
If _WindowHasFocus = 0 Then _Continue
End If
If (exclude_code And 2) = 0 Then 'mouse clicks break pause
While _MouseInput: Wend
If _MouseButton(1) Or _MouseButton(2) Then Exit Do
End If
If (exclude_code And 4) = 0 Then 'we allow keyboard input (of some sort) to break pause
k = _KeyHit
If (exclude_code And 8) Then If k < 0 Then k = 0 'but we don't allow keyup events to do it
If (exclude_code And 16) Then 'here we don't allow modifier keys to do it
Select Case k
Case 100304, 100303, -100304, -100303 'shift up/down
_Continue
Case 100306, 100305, -100306, -100305 'ctrl up/down
_Continue
Case 100308, 100307, -100308, -100307 'alt up/down
_Continue
End Select
End If
End If
If time <> 0 And Timer > t# Then Exit Do
If k <> 0 Then Exit Do
Loop
End Sub
And here we have a customizable "Pause" routine, which allows for a few things which SLEEP doesn't.
Set it to allow mouse clicks to break pause.
Set it to allow pause to only break when the window has focus.
Remove modifier keys from the list of acceptable keys to break pause (no shift/ctrl/alt breaking pause).
Set it so that only keydown events break pause and not keyup events.
Timed events, or events without no time limit.
One thing of note: This also allows you to create your very own endless loop! Set it with no time limit for a pause, with no input allowed to break the pause, and you have permanently paused your program until you click the red "X" in the top right corner and closed it.
I really wouldn't recommend doing that, but hey, if that's your thing....
|
|
|
Linux HTTP WEB Server Issues - Large Files Fail |
Posted by: old_coder - 03-27-2024, 08:33 PM - Forum: Help Me!
- No Replies
|
|
New to this portal, but been coding for a while.
Tried to search for assistance but found nothing directly related to my issues - may not be asking the correct questions.
Looking for any available assistance with web services in Linux.
Created a WEB based music JukeBox (plan to release code when it is de-kluged) on my Windows machines. Works great on XP & Windows 10.
System is designed so the music playing appliance is a web server, and users can search / add to que / add to playlists via a WEB interface.
Core HTTP handling code was based on luke's simple HTTP server - nicely written and easy to expand from,
Recently added options to play music locally (download & play in the WEB browser). Works great on Windows based server, but messes up badly on Linux Based server - downloads never complete or data gets jumbled.
All WEB pages are HTML coded in text strings, assembled into packets that are downloaded to the client. I thought this works great on Linux, but testing confirmed large file HTML downloads have the same issue
Windows box is a clunker XP Pro machine (64 bit) with 2 GB ram.
Linux box is a Raspberry Pi4 with 4 GB ram.
Pi4 responds to searches 3 - 4 times faster - excellent portable JukeBox!
Every other coded function / WEB function works correct, including HTML page downloads etc AS LONG AS THE DOWNLOAD IS SMALL.
Trying to confirm if this is an error I can work around, a legitimate bug, or something I am missing
Any comments on Linux side WEB server issues will be appreciated.
|
|
|
Made my first AI project today. |
Posted by: Pete - 03-26-2024, 08:41 PM - Forum: General Discussion
- Replies (3)
|
|
It's a robot golfer. So far, all I can get it to learn is to pound its club repeatedly on the ground, but that's got 90% of the people at my country club completely fooled into thinking it's a real golfer. Now if I can just get it to pee standing up. Hopefully soon. The price of oil isn't getting any cheaper.
Pete
|
|
|
|