Author Topic: Invalid handle error on Screen command after 5 minutes  (Read 4268 times)

0 Members and 1 Guest are viewing this topic.

Offline madscijr

  • Seasoned Forum Regular
  • Posts: 295
    • View Profile
Re: Invalid handle error on Screen command after 5 minutes
« Reply #15 on: May 28, 2021, 06:48:37 pm »
To make a console in QB64 you need to use the metacommand $CONSOLE. You toggle it ON or OFF with _CONSOLE ON or _CONSOLE OFF. _ECHO allows you to output to the window. So _ECHO "Window Handle: "; STR$(imgScreen&)
I'm definitely going to try this, as soon as I am back on the PC.
Thank you!

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Invalid handle error on Screen command after 5 minutes
« Reply #16 on: May 28, 2021, 07:51:14 pm »
I am so clueless. What's a canvas image? I thought they were all just images?
The reason I set SCREEN above, is to simply unlock the imgScreen& so I can _FREEIMAGE it, so when I copy the layers onto it, there aren't all those copies.
I am really confused.

Would you maybe be able to post a simple example or point me to one?

Thanks again

UPDATE:
Maybe I am using _CopyImage when I really need to be using _PutImage ... When I get back on the computer I will look that up. Thank you all for being so kind and patient with one so thick headed.

Yes, _PUTIMAGE is your friend. You should only have to set SCREEN once and then put images on it, CLS, _DISPLAY, etc.

I think what Fellippe is referring to as a "canvas" would be like the image 'underlay' in the crude example below:

Code: QB64: [Select]
  1. DIM underlay AS LONG
  2. DIM overlay AS LONG
  3.  
  4. underlay = _NEWIMAGE(400, 400, 32)
  5. overlay = _COPYIMAGE(underlay)
  6.  
  7. _DEST underlay
  8. LINE (50, 125)-(75, 275), &HFF00FF00, BF
  9. LINE (325, 125)-(350, 275), &HFF00FF00, BF
  10.  
  11. _DEST overlay
  12. LINE (175, 50)-(225, 350), &HFFFF0000, BF
  13.  
  14. box = -50
  15. SCREEN _NEWIMAGE(400, 400, 32)
  16.  
  17.     _PUTIMAGE , underlay, 0
  18.     box = box + 1
  19.     IF box > 400 THEN box = -50
  20.     LINE (box, 175)-(box + 50, 225), &HFF0000FF, BF
  21.     _PUTIMAGE , overlay, 0
  22.     _DISPLAY
  23.     _LIMIT 50
  24. _FREEIMAGE underlay
  25. _FREEIMAGE overlay
  26.  

Offline madscijr

  • Seasoned Forum Regular
  • Posts: 295
    • View Profile
Re: Invalid handle error on Screen command after 5 minutes
« Reply #17 on: May 29, 2021, 12:04:19 am »
Yes, _PUTIMAGE is your friend. You should only have to set SCREEN once and then put images on it, CLS, _DISPLAY, etc.
I think what Fellippe is referring to as a "canvas" would be like the image 'underlay' in the crude example below:

Your example was fine - I replaced all the extra _COPYIMAGE commands with _PUTIMAGE and it works.
Thanks for explaining!

Offline madscijr

  • Seasoned Forum Regular
  • Posts: 295
    • View Profile
Re: Invalid handle error on Screen command after 5 minutes
« Reply #18 on: May 29, 2021, 12:07:11 am »
To make a console in QB64 you need to use the metacommand $CONSOLE. You toggle it ON or OFF with _CONSOLE ON or _CONSOLE OFF. _ECHO allows you to output to the window. So _ECHO "Window Handle: "; STR$(imgScreen&)

I tried it, and it's a good way to quickly and easily monitor / debug a program.
Thanks for the tip!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Invalid handle error on Screen command after 5 minutes
« Reply #19 on: May 31, 2021, 07:15:11 pm »
@madscijr
What is the state of art of your program?
Programming isn't difficult, only it's  consuming time and coffee

Offline madscijr

  • Seasoned Forum Regular
  • Posts: 295
    • View Profile
Re: Invalid handle error on Screen command after 5 minutes
« Reply #20 on: June 01, 2021, 01:52:51 pm »
@madscijr
What is the state of art of your program?

I'm not sure what you mean.
I wouldn't say it's the state of THE art, if that's what you mean, lol.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Invalid handle error on Screen command after 5 minutes
« Reply #21 on: June 01, 2021, 01:57:48 pm »
Yeah, I think he's just asking if you have an update.

Offline madscijr

  • Seasoned Forum Regular
  • Posts: 295
    • View Profile
Re: Invalid handle error on Screen command after 5 minutes
« Reply #22 on: June 01, 2021, 02:07:17 pm »
Yeah, I think he's just asking if you have an update.

Aha. Well, the problem this thread was about is definitely resolved, and I will be posting the fixed code, it's just in an "inbetween" state right now... Stay tuned!

Offline madscijr

  • Seasoned Forum Regular
  • Posts: 295
    • View Profile
Re: Invalid handle error on Screen command after 5 minutes
« Reply #23 on: June 01, 2021, 02:54:12 pm »
@TempodiBasic @bplus @SpriggsySpriggs @FellippeHeitor @OldMoses

Here is the latest, which no longer crashes now that the _COPYIMAGE has been replaced with _PUTIMAGE.

To try it, choose option 5 from the menu. It now has scrolling!
The exits to the next level (ladders down) are not yet implemented,
so to advance to the next level of the game (not really a game yet, all you can do is walk around),
press <ESC> to return to the menu, then select option 5 again, and it will open to the next level,
with different monsters and a progressively harder maze.

Currently there's a minor but annoying bug where for some reason, a water tile is being rendered to the top left (1,1) space in the game window.
What's weird is that the normal terrain for that space gets rendered, and this other tile gets superimposed over it!
I have no idea what is doing this, will have to track that down.

Note that the code is due for some major cleanup, and there is duplicate code such as 2 main loops -
a mostly disabled main loop from the "50 line Roguelike", and the original main loop from the demo.
All that needs to be merged together, and the game logic needs to be enabled & made working.

Thanks to all of you for your help.
« Last Edit: June 01, 2021, 03:02:50 pm by madscijr »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Invalid handle error on Screen command after 5 minutes
« Reply #24 on: June 02, 2021, 02:02:42 pm »
I'm not sure what you mean.
I wouldn't say it's the state of THE art, if that's what you mean, lol.
Thanks madscijr you have showed me that the same phrase has two different meanings in English and in Italian.
What Bplus says about my message is what the state of the art meaning into italian language... at what point is your work
and here I have learned what this phrase meaning in English  language and its evolution from 1800 to now.
https://www.linkiesta.it/2016/09/lo-stato-dellarte-dallinglese-allitaliano-spiegato-dalla-crusca/

It is always a pleasure to learn something new.
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Invalid handle error on Screen command after 5 minutes
« Reply #25 on: June 02, 2021, 02:17:01 pm »
@madscijr
about game... fine, I see you prefer to use black color for background of images.

I you're interested to use different colors as background and you want don't cover background image of the screen with the background of the image by _PUTIMAGE I suggest to you to give a look to _RGBA32 colors and to the related commands for Alphacolor tecniques  here http://qb64.org/wiki/Keyword_Reference_-_By_usage#Colors_and_Transparency.
Programming isn't difficult, only it's  consuming time and coffee

Offline madscijr

  • Seasoned Forum Regular
  • Posts: 295
    • View Profile
Re: Invalid handle error on Screen command after 5 minutes
« Reply #26 on: June 02, 2021, 03:40:33 pm »
@madscijr
about game... fine, I see you prefer to use black color for background of images.

I you're interested to use different colors as background and you want don't cover background image of the screen with the background of the image by _PUTIMAGE I suggest to you to give a look to _RGBA32 colors and to the related commands for Alphacolor tecniques  here http://qb64.org/wiki/Keyword_Reference_-_By_usage#Colors_and_Transparency.

Thanks for the info - that will come in handy. I am using black for the _screen_ background, but the tilesets are actually PNG with transparent backgrounds, and when I was using a non-black (graph paper) background, I think you could see the background underneath the parts that were transparent.
I'm going to look at this again, because I want to layer tiles depending on what is in a given space (eg if someone is walking in a wooded area (trees) that terrain would be rendered _over_ the player tile, versus if they are walking on grass, those tiles would be rendered _under_ the player, etc.)

This is a ways off, right now I'm dealing with more the basic mechanics of making the game playable and fixing bugs.

Thanks again, I am sure I will have some follow up questions when I get to it...
« Last Edit: June 02, 2021, 03:44:03 pm by madscijr »

Offline madscijr

  • Seasoned Forum Regular
  • Posts: 295
    • View Profile
Re: Invalid handle error on Screen command after 5 minutes
« Reply #27 on: June 02, 2021, 03:45:25 pm »
Thanks madscijr you have showed me that the same phrase has two different meanings in English and in Italian.
What Bplus says about my message is what the state of the art meaning into italian language... at what point is your work
and here I have learned what this phrase meaning in English  language and its evolution from 1800 to now.
https://www.linkiesta.it/2016/09/lo-stato-dellarte-dallinglese-allitaliano-spiegato-dalla-crusca/

It is always a pleasure to learn something new.

Indeed it is, that's very interesting.  No worries!

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Invalid handle error on Screen command after 5 minutes
« Reply #28 on: June 03, 2021, 01:14:14 pm »
One thing you might look into doing that might help the read-ablitiy of your program is creating a data file and loading that rather than setting all the data with in your main program.
For example:
Code: QB64: [Select]
  1.     arrNPC(1, 1).Name = "Child"
  2.     arrNPC(1, 1).TileNum = cTileChild1%
  3.     arrNPC(1, 1).Frequency = 100
  4.     arrNPC(1, 1).Behavior = "it"
  5.     arrNPC(1, 1).Talk = "Are you going to save the people?"
  6.     arrNPC(1, 1).Yell = ""
  7.  
you have over 1000 lines of your main program made up of this data alone, if you moved all that to a second program that saved it to a file you could load from that file with 3 lines as follows
Code: QB64: [Select]
  1. OPEN "NPCDATA.DAT" FOR BINARY AS #1
  2. GET #1, ,arrNPC()

and there you save over a 1000 lines of code, reduce the length of your main program so it is easier to navigate and read, while too allowing easier changing of data at a later date by having it all in one location rather then scattered through out the main code.

You can do that with any BULK data that you use within your game, which could probably reduce your main code by several thousand lines and tens of thousands of bytes. 
A good example of this is my Dragon Warrior clone, if you check it out you will see I have 2 program source files;
--DW1_FullSource.bas  which is the main program,
and a second
--DRAGONWARRIORDATA.BAS which is all the data for the game.

Your project looks very interesting though, can not wait to see it finished.
Granted after becoming radioactive I only have a half-life!

Offline madscijr

  • Seasoned Forum Regular
  • Posts: 295
    • View Profile
Re: Invalid handle error on Screen command after 5 minutes
« Reply #29 on: June 03, 2021, 02:46:30 pm »
One thing you might look into doing that might help the read-ablitiy of your program is creating a data file and loading that rather than setting all the data with in your main program.
For example:
Code: QB64: [Select]
  1.     arrNPC(1, 1).Name = "Child"
  2.     arrNPC(1, 1).TileNum = cTileChild1%
  3.     arrNPC(1, 1).Frequency = 100
  4.     arrNPC(1, 1).Behavior = "it"
  5.     arrNPC(1, 1).Talk = "Are you going to save the people?"
  6.     arrNPC(1, 1).Yell = ""
  7.  
you have over 1000 lines of your main program made up of this data alone,

Thanks for the tip.
I have considered moving the data to separate files, just haven't got there yet (same with reusable functions, separated into libraries).
I always liked code that is "type in friendly" or copy+paste friendly (who in their right mind is going to type in 15,000 lines?!)
and putting everything in one file makes it simpler from that standpoint.
I don't even like having the tilesets & bitmap fonts in separate PNG files!

I get that in some ways it's easier to navigate smaller files,
but it is also more complicated when you have to worry about multiple files and formats,
and manage a project and dependencies. I know one big file with 20,000 lines gives people a headache,
but a project with 50 subfolders and a million files gives ME a headache, lol.
So anyway, that's why it's one big file and my approach so far has been geared toward "all in one".

if you moved all that to a second program that saved it to a file you could load from that file with 3 lines as follows
Code: QB64: [Select]
  1. OPEN "NPCDATA.DAT" FOR BINARY AS #1
  2. GET #1, ,arrNPC()
and there you save over a 1000 lines of code, reduce the length of your main program so it is easier to navigate and read, while too allowing easier changing of data at a later date by having it all in one location rather then scattered through out the main code.
You can do that with any BULK data that you use within your game, which could probably reduce your main code by several thousand lines and tens of thousands of bytes. 

I see your example uses a binary format, which is more compact.
For my purposes, I would prefer to use plain text in a human readable, easily editable format.
Multiple files aren't off the table, but I would prefer for them to be editable as plain text - even the tilesets!

I considered JSON, but I haven't yet seriously looked for any QB64 / QBasic jsonify / stringify functions
(and I don't really want to write them!)
A while back I found Jsonify/Stringify for VBScript and I have used them in VBA,
but they rely on nested Dictionary objects (associative arrays).
I tried creating my own associative array in QB64 few months back,
but it was buggy and clunky, and I haven't been too excited about slogging through that.

Also, although JSON is a simple format for us programmers, it might be too complicated for kids and their parents.
I want this to be editable by non-programmers and kids. I just feel like JSON is simple, but not simple enough.

I might go with your basic DOS config file format, something like
Code: [Select]
Level=1
Name=Child
TileNum=cTileChild1%
Min=1
Max=1
Behavior=it
Talk=Are you going to save the people?
Yell=

Level=1
Name=Child
TileNum=cTileChild2%
Min=1
Max=2
Behavior=it
Talk=Please save us from the monsters!
Yell=


I haven't gotten there yet.
A lot of this program is messy and ugly and inefficient and a WIP, and I'll clean it up as I go.
For now I am just working to get a basic playable game.

A good example of this is my Dragon Warrior clone, if you check it out you will see I have 2 program source files;
--DW1_FullSource.bas  which is the main program,
and a second
--DRAGONWARRIORDATA.BAS which is all the data for the game.

Thanks, I will give it a look!
The next thing I think I need to really figure out is D&D or Ultima style combat,
calculating hit/miss, damage, etc. based on player attributes (strength, agility, etc.),
different weapons, armor, skills, etc.
It's been a loooooong time since I played basic D&D and I don't remember how it worked,
but this should work kind of like classic Ultima or D&D.
There's an article I found
https://datadrivengamer.blogspot.com/2019/09/the-basic-mechanics-of-ultima.html
that might help.

Your project looks very interesting though, can not wait to see it finished.

Thanks - so far it isn't that remarkable, but the ultimate goal of this is to create something
that's lets people EASILY and SIMPLY create games that are a mix between classic Ultima and Infocom text adventures
(where they can control how much of the one or the other),
in the form of a construction set - think Electronic Arts' Adventure Construction Set,
but with simpler editing, using text files instead of the clunky joystick interface and the proprietary hidden data file formats that ACS used.
« Last Edit: June 03, 2021, 03:52:45 pm by madscijr »