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 / Dbpro mousemove problems

Author
Message
Nemesis
21
Years of Service
User Offline
Joined: 18th Sep 2002
Location: Australia
Posted: 18th Sep 2002 16:49
Well here's my problem:


That will return a value of 0 for both of them, even though it clearly isn't becuase it wouldn't have even prited the number 0 otherwise. If you try printing it straight without satisfying any condition it prints fine however, as it does with a different condition such as x=1. I know that DBpro is still in it's early stages, so I expected problems like this off the shelf. Just letting ya know.
http://homepages.ihug.com.au/~nemesis2k2/junk/nemesis.gif[/img]
las6
21
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Finland
Posted: 18th Sep 2002 17:06
first I thought that you were wrong, but I checked that out... very odd indeed.

you can get that code to work by first assigning the mousemove value to a variable, then doing the if check on the variable.

Specs :: [1333Mhz : 256DDR : Geforce 2 Mx 64MB]
Nemesis
21
Years of Service
User Offline
Joined: 18th Sep 2002
Location: Australia
Posted: 18th Sep 2002 17:30
Yeah I know. That's what I'm doing for it now. It's quite a weird problem that I thought would most likely not be picked up for awhile if I didn't report it though.

I know everything! At least I don't know anything I don't know.
Zep
21
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 18th Sep 2002 20:59
um...in the "GOD where did you people learn to CODE department."

sync on
do
if mousemovey()=0 then else print mousemovey()
if mousemovex()=0 then else print mousemovex()
set cursor 0,0
sync
cls
loop

what kind of coding style is that? I'd say the compiler should reject that code as being stupid.

The compiler should reject the "then else" combo since you have nothing to "then"

At least THIS way it makes sense. (and probably WORKS as expected, too.

do
if mousemovey()>0 then print mousemovey()
if mousemovex()>0 then print mousemovex()
set cursor 0,0
sync
cls
loop

Zep--

Nemesis
21
Years of Service
User Offline
Joined: 18th Sep 2002
Location: Australia
Posted: 19th Sep 2002 04:31
Actually, that string of code will be interpreted fine. All it will do is most likely create a redundant JMP command when it compiles to ASM. Your string of code OTOH is crap becuase it only detects positive mouse movement. The alterntaive would be:

if mousemovey()>0 or mousemovey()<0 then print mousemovey()
if mousemovex()>0 or mousemovex()<0 then print mousemovex()

I can guarantee that the whole extra check there will eat up more clock cycles than just a redundant jump. Before you go criticizing other people's coding, make sure you know what you're on about. You don't have to use the syntax exactly as it was meant to be used if you know how the commands work. You obviously don't, or else you'd see that what I've written would work fine, and would be more efficient.

PS: Your string of code returns 0 as well, try testing something before posting it.

I know everything! At least I don't know anything I don't know.
Nemesis
21
Years of Service
User Offline
Joined: 18th Sep 2002
Location: Australia
Posted: 19th Sep 2002 04:52
Meh, I think I'll patronise you further. You see all that my if then else statement would do is first a BNE command, and that would execute an offset based jump to the section of code which in the editor is indexed by the "then" command (which is not really a command, but a marker). The program would then continue from that point until it hits a JMP command, which would link to the next line of code after the if then else statement. If they are equal, the code most likely continues straight after the check, so the else set of commands would most likely be stored first rather than second (although this depends on the compiler, but that's how I'd structure it). It would then hit a JMP command at the end of it's command list, and that would jump to the next line as well, so in fact there wouldn't be any redundant jump if that's the way the code is structured.

Ok, I've finished now. Next time don't try to show up someone unless you know what you're talking about.

I know everything! At least I don't know anything I don't know.
Nemesis
21
Years of Service
User Offline
Joined: 18th Sep 2002
Location: Australia
Posted: 19th Sep 2002 07:30
Ok, here's the source of the problem. DBpro seems to be resetting the value of mousemovex and mousemovey to 0 after you've called them once, so it's a problem with the mousemove functions themselves.Take this for example:



One will showup fine, but two almost never does. Occasionally two will flash on for like one frame, which in itself is weird. If it just never came on it would make more sence, but whatever.

I know everything! At least I don't know anything I don't know.
Zep
21
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 19th Sep 2002 16:16
Try to justify bad coding style all you want, it isn't flying here.

My point was not to compare if mousemove was greater or less than 0, the point was to show you how to code an if statement properly.

And as far as optimizing it

sync on
do
if mousemovey() then print mousemovey()
if mousemovex() then print mousemovex()
set cursor 0,0
sync
cls
loop

No check on the value needed at all.

Zep--

Nemesis
21
Years of Service
User Offline
Joined: 18th Sep 2002
Location: Australia
Posted: 19th Sep 2002 16:45
My point is there is no "proper" way to use it. An if statement is a very basic command set that compiles to a command like BNE or BEQ and a couple of non conditional jumps. It doesn't matter how it looks in it's code form, it matters how it's set out when it's compiled, and there was nothing wrong syntactically wrong with the way it was setout, it was simply unconventional.

I however did not know that you could leave out the condition all together, so I will thank you for that tip. Next time however try offering an alterntaive rather than outright criticizing someone. I may be new to the basic syntax but I am not new to this stuff, I've merely focused on other areas.

I know everything! At least I don't know anything I don't know.
Zep
21
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 19th Sep 2002 18:29
this strng of code will be "interpeted" fine too,and run, doesn't mean it's right.

for t = 1 to 100
for x = 1 to 100
next t
next x

And there is a proper way to do it, from db help files:

SYNTAX
IF Condition THEN Command Go Here for condition True

SYNTAX
IF Condition
Command Go Here for condition True
ELSE
Command Go Here for condition False
ENDIF

Zep--

MrTAToad
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 19th Sep 2002 18:56
Doing things the wrong way is a very good way of testing programs - by all accounts the compiler should have flagged the two lines as an error because there should have been text between the 'then' and 'else' commands - it wouldn't really know what machine code to put in.
I believe another bug has been found in the compiler...

Yes, I really am THAT good...
Nemesis
21
Years of Service
User Offline
Joined: 18th Sep 2002
Location: Australia
Posted: 20th Sep 2002 04:26
Quote: "this strng of code will be "interpeted" fine too,and run, doesn't mean it's right.

for t = 1 to 100
for x = 1 to 100
next t
next x"

Well if you could somehow use that peice of code to perform a task you wanted it to do, what would be the problem with it? Just becuase a command is suppost to be used one way doesn't mean that you can't use it completely differently to achieve a different result. As long as you get the output you want from it, there's nothing wrong with it IMO.

Quote: "the two lines as an error because there should have been text between the 'then' and 'else' commands - it wouldn't really know what machine code to put in. "

It doesn't need to put in any code, that's what I'm trying to tell you. All an if then else does is change where the next command is being read from. There is nothing wrong with leaving it blank.


Gah, I tire of this. If/when you learn some assembly you'll see that the structure of the code is effectively the same when compiled regardless.

I know everything! At least I don't know anything I don't know.
Zep
21
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 20th Sep 2002 04:52
From my resume:

Education

Computer Programming - GPA 3.2 (Major)
Some courses taken include ASSEMBLER, C 1 & 2, COBOL 1 & 2, FORTRAN, BASIC 1 & 2, Systems Programming & Database Programming on a variety of platforms.

If and when *YOU* learn how to code right, please open your mouth again.

Zep--

Zep
21
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 20th Sep 2002 05:02
and btw, Mr Assembler

for t = 1 to 100
for x = 1 to 100
next t
next x

would crash if compiled as is in assembler. when the loop finally did reach next x, next t would branch to an invalid address.

Zep--

VietStylist
21
Years of Service
User Offline
Joined: 20th Sep 2002
Location: Australia
Posted: 20th Sep 2002 15:54
Whoa ho!!! You got bomb out to the days man! I don't think I'll be technically messing with him (lol).

Vs

Nemesis
21
Years of Service
User Offline
Joined: 18th Sep 2002
Location: Australia
Posted: 20th Sep 2002 16:53
Well that explains your overinflated ego. I'm sorry but some list of accolades doesn't impress me. I respect people who respect others. Next time you feel like correcting someone, do it to teach them, not to stroke your own ego and impress others. I'd quote from my resume, but I don't fucking have one. You know why? Becuase I'm 16, and admittedly still learning all this shit.

Look, feel free to correct me and offer advice, but at least try and cut the insults when you do it. I'm here to learn, not to get slammed for my mistakes.

I know everything! At least I don't know anything I don't know.
MrTAToad
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 20th Sep 2002 17:00
I feel it was a good example, not only of finding a problem with the mouse commands, but also with the actual compiler.

You should sometimes do things the incorrect way just to see if what your testing is robust and correct.

Yes, I really am THAT good...
Zep
21
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 20th Sep 2002 17:04
Look, feel free to correct me and offer advice, but at least try and cut the insults when you do it. I'm here to learn, not to get slammed for my mistakes.

Quit insisting your mistakes are "right" then. Your first bit of code was a HORRIBLE example of basic code.

and as for this:

sync on
do
if mousemovex()<>0 then print "one"
if mousemovex()<>0 then print "two"
sync
cls
set cursor 0,0
loop

One will showup fine, but two almost never does. Occasionally two will flash on for like one frame, which in itself is weird. If it just never came on it would make more sence, but whatever.


Ever stop to think that the CODE is is going too fast, checking the second mousemove command before you actually have a chance to MOVE the mouse faster than the code is checking for it?

Zep--

Zep
21
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 20th Sep 2002 17:24
another thing, if you would have used IF ELSE as it should be used, you would have had no trouble with the code in the first place



Mr Toad, the problem isn't with the compiler in this case, the problem is between the coders ears.

Zep--

Zep
21
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 20th Sep 2002 17:30
or even closer to his original sample, this:



MrTAToad
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 20th Sep 2002 18:00
The compiler should have detected the problem in the first place, which makes the code quite valid for testing the compiler.

Yes, I really am THAT good...
Zep
21
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 20th Sep 2002 18:16
That's debatable if it's a compiler error or not.

SYNTAX
IF Condition THEN Command Go Here for condition True

In his first example the THEN is satisfied by having a command after it.

Bad logic/syntax broke the code by using an ELSE after what he wanted to be an empty THEN.

That's how I see it.

Zep--

MrTAToad
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 20th Sep 2002 18:34
I do think its a compiler error, because otherwise it would just be a one-sided conditional statement that only accepts false comparisons, which is not how IF/THEN statements work.

Yes, I really am THAT good...
Nemesis
21
Years of Service
User Offline
Joined: 18th Sep 2002
Location: Australia
Posted: 20th Sep 2002 18:37
In the original DB, when you called the mousemove function it did not start recalculating the mouse movement again from that point. The fact that it does in DBpro is an annoyance becuase in order to make much use out of that function at all now it has to be stored in a variable, which is not some kind of severe limiting factor, merely an inconvenience.

That is what I was talking about. If you entered the string of code

Into DB both would be on solid all the time. Whether it's DBpro or the original DB that had an error depends on how you believe the mousemove function is suppost to work.

I know everything! At least I don't know anything I don't know.
MrTAToad
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 20th Sep 2002 18:46
Probably one of them is getting the data from the mouse buffer, instead of directly. Cant say which is correct!

Yes, I really am THAT good...
Zep
21
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 20th Sep 2002 19:13
sync on
do
x=mousemovex()
wait 1
y=mousemovex()
print "x=",x,"y=",y
if x <> y then print "you are wrong!"
sync
cls
set cursor 0,0
loop

even without the WAIT it will still tell you you are wrong at some point, the code is executing faster than you can slow the mouse down.

Zep--

Nemesis
21
Years of Service
User Offline
Joined: 18th Sep 2002
Location: Australia
Posted: 20th Sep 2002 19:38
Ahh, now I see it. The interpretation in the original DB just ran so slow you couldn't tell the difference.

I know everything! At least I don't know anything I don't know.

Login to post a reply

Server time is: 2024-05-04 01:35:20
Your offset time is: 2024-05-04 01:35:20