Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Trouble with input statements after checking for a file

Author
Message
Knifeworld
10
Years of Service
User Offline
Joined: 28th Sep 2014
Location: England
Posted: 22nd Oct 2014 17:36
Hello, i'm hitting a brick wall where i cannot continue with input statements after calling a function to check for the existence of a file.

the first input statement asks what image i want to load.

Imediately after this statement i call a function to check it exists.

Everything in my code works fine (except the main thing i'm trying to do with it, but that could cover several other posts and topics! XD!)

Even a similar function to manage directories works perfectly...

...the check function works great if the image doesn't exist, it jumps back to the _getimage sub routine and the first input statement comes back.

If the image DOES exist, then the screen freezes and i can't see what's going on, and i have to manually shut down the program.



Spooky Data
Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 23rd Oct 2014 01:20
A program in which you have set sync on will not properly swap the backbuffers while drawing text; it is up to you to ensure that the text is drawn to it for each frame (ie. draw the text in each loop cycle).
However the nature of the input command is such that it pauses the execution of your function until the user presses the return key, thus preventing you to manually call sync until the input is completed.
You basically have two choises; let the engine automatically synchronize (sync off) while you are accepting input, or write your own input routine that reads one character at a time (or none if no key is pressed) until the return key is pressed. This allows you much greater control of the input as well as lets you control other things while taking input, so I would very much advocate that approach. If you're only just beginning the first approach is simpler though for getting something up and running to start with

ShellfishGames
12
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 25th Oct 2014 21:47 Edited at: 25th Oct 2014 21:53
I believe the problem is that your load bitmap command in case the image exists will probably set the loaded bitmap as current bitmap, i.e. all draw commands after that will be directed to that bitmaps.

Hence what you need to do, if I am not mistaken, is write set current bitmap 0 just behind the load bitmap command. (By the way, I don't quite know what you're trying to do with the code (and didn't really bother to understand it, ain't nobody got time for that ), but it's quite possible that the image commands will be the better choice instead of bitmaps. If you know the difference between bitmap and image commands, just ignore what I'm saying, but if you don't, chances are load image, paste image etc. are what you should actually use)

About what Rudolpho said, I don't think there's a problem with using sync on and the input command. I have used both commands in many different projects at the same time without problems. The only time your input will now show up is when there wasn't a single sync call between sync on and input, otherwise it works fine.

Edit: And just a minor thing - did you define "true" as a constant somewhere in your code? Or as global variable? This isn't the case in the snippet you posted, so if you forgot that, all your if statements will invert their condition. Also you don't really need the "= true", you can just write "if something" and it will evaluate to true if something is not zero. If you prefer the "= true" form, go ahead of course, but you don't necessarily need it in your code.

Knifeworld
10
Years of Service
User Offline
Joined: 28th Sep 2014
Location: England
Posted: 27th Oct 2014 02:28
thank you for the advice & ideas.


I should try running input statements in a subroutine immediately after the display setup and before the main loop.
i have done it that way at least once before.

I actually sorted out the faulty screen during the input process myself not long after posting. But i think it could be improved yet more by trying your suggestions.

Yes, i always use globals for true and false, and for black background and white text too hah.


So here goes some explanations and such:

I was happy with input cmds being in a gosub inside the main loop because you
see the clock changing and at any time you can choose to go to that process
or to exist by pressing space.
So it felt like it was running and not just a blank screen with some questions, if you know what i mean!

it's only the displayed time that freezes after jumping to the process,
but any other altering visuals would freeze too probably.

When the input is finished, it jumps to an end of program label "_endprog"
...the only place i ever use Goto, cause it is the end, haha.

The structure of the code was borrowed from 8 previous programs.
But maybe it needs to change to fit each type of thing i want to do, probably a good idea LOL!


This program is detecting edges in a bitmap, pat of why i was starting off by using load bitmap.

it creates two blank files that i make into bitmaps.
One is a copy of the loaded image and the second is a changed image
based on some byte-level calculations and lots of Point(x,y) commands.

i'm not set on displaying anything until i'm happy with the
part of the code that has all the bit-shifting and point(x,y) variables.

But maybe i will try displaying them anyway since i sorted out the faulty input process.

I'll try doing it with image commands and without sync on too.


This is the altered code than ran better, with some commands cut out so you just see how it's structured:




Spooky Data
ShellfishGames
12
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 28th Oct 2014 01:10
Quote: "The structure of the code was borrowed from 8 previous programs.
But maybe it needs to change to fit each type of thing i want to do, probably a good idea LOL!"


That.. really made me laugh.

And just one more thing about the sync... I don't think not using sync on would benefit you in any way (apart from not having to write sync after a few print statements maybe). Input syncs automatically. The only thing you should probably do, is write a single sync call just behind sync on, because the first sync doesn't actually update the screen, so your first input statement behind the sync on possibly wouldn't be visible. But that's really all there is to it as far as I'm concerned.

Knifeworld
10
Years of Service
User Offline
Joined: 28th Sep 2014
Location: England
Posted: 29th Oct 2014 02:45
hahaha!

Yeah, i haven't worked on the other programs for quite a while so the code in this one is becoming a lot different.

i managed to fix the input/display error and most importantly for the end purpose of the program itself i finally got it to work the way i wanted, so now i have myself a cool edge detecting program.

i noticed today that if you type the image name wrong the program messes up when it returns to the start of the input gosub again, not sure what is going wrong but i'd like to know!

But for now, in the interest of a stable version 2 of the program, i'm happy with just making it end the program instead of jumping back to the start of the gosub.


while typing this i had trouble displaying the loaded image as a sprite because it was covering text, but not only did i fix that i also coded a very smooth and simple function to only display available images and nothing else. Sometimes i surprise myself..

this is the code for that, if anyone might find it useful



Spooky Data

Login to post a reply

Server time is: 2025-05-12 10:17:43
Your offset time is: 2025-05-12 10:17:43