Coding

 Reply to this postStart new topic

Problem with cycle

greatvova
post Jul 12 2014, 01:40 PM
Post #1


The New Guy!

Posts: 2
Joined: 12-July 14



QUOTE
WHILE 0AB0: key_pressed 220 // work untill "\" pressed
wait 0
0ACD: show_text_highpriority "Script is now running !!!" time 2000
wait 1000
0AA5: call 1@ num_params 4 pop 0 0 0 0 0x0D //??????
wait 1000
0AA5: call 1@ num_params 4 pop 0 0 0x02 0 0x0D //??????

if 0AB0: key_pressed 220 //Stop if "\" is pressed
break

END


What is wrong with it??
Go to the top of the page
 
+Quote Post
Deji
post Jul 12 2014, 06:25 PM
Post #2


Coding like a Rockstar!

Group Icon

Posts: 1,468
From: ???
Joined: 28-May 09



QUOTE (greatvova @ Jul 12 2014, 02:40 PM) *
What is wrong with it??


Plenty of things. My popular objection at the moment is the excessive use of WAIT, however, while I still think its involvement is excessive in this script and will make it run badly, I think you're after a different answer...

QUOTE
WHILE 0AB0: key_pressed 220 // work untill "\" pressed

This doesn't work UNTIL the key is pressed, it works WHILE the key is pressed, which is a big difference. You probably meant it to work WHILE the key is NOT pressed.

Moreover, there's still quite a big difference in something working UNTIL something and something working WHILE something is NOT. In programming, this works very literally, so you have to make sure you know the difference. If something works UNTIL a condition, it means it works once anyway, and then the condition determines whether it will do that work again, if something works WHILE the condition is 'NOT' (as in not true), it will not run at all unless the condition starts-off true. Without more of your code or a description of what needs to happen, I can't tell which one you want, so I'll just show you the easiest modification, which is to get it to work WHILE the condition is NOT true.

You simply negate the conditional opcode:
CODE
WHILE 8AB0:   NOT key_pressed 220 // work untill "\" pressed

Since you're using SB without keywords, you need to manually change the opcode to be prefixed with '8' - in which case the 'NOT' is actually just for description. If you were using a better language, which SB can partially support through keywords, you'd simply only have to use 'NOT' which is way more readable. However, I'm sure you probably just want a quick fix and not a suggestion on how to improve your whole way of writing code, so try fixing that simple issue first and see if it resolves the problem.


--------------------
Go to the top of the page
 
+Quote Post
greatvova
post Jul 12 2014, 10:01 PM
Post #3


The New Guy!

Posts: 2
Joined: 12-July 14



QUOTE (Deji @ Jul 12 2014, 09:25 PM) *
Plenty of things. My popular objection at the moment is the excessive use of WAIT, however, while I still think its involvement is excessive in this script and will make it run badly, I think you're after a different answer...


This doesn't work UNTIL the key is pressed, it works WHILE the key is pressed, which is a big difference. You probably meant it to work WHILE the key is NOT pressed.

Moreover, there's still quite a big difference in something working UNTIL something and something working WHILE something is NOT. In programming, this works very literally, so you have to make sure you know the difference. If something works UNTIL a condition, it means it works once anyway, and then the condition determines whether it will do that work again, if something works WHILE the condition is 'NOT' (as in not true), it will not run at all unless the condition starts-off true. Without more of your code or a description of what needs to happen, I can't tell which one you want, so I'll just show you the easiest modification, which is to get it to work WHILE the condition is NOT true.

You simply negate the conditional opcode:
CODE
WHILE 8AB0:   NOT key_pressed 220 // work untill "\" pressed

Since you're using SB without keywords, you need to manually change the opcode to be prefixed with '8' - in which case the 'NOT' is actually just for description. If you were using a better language, which SB can partially support through keywords, you'd simply only have to use 'NOT' which is way more readable. However, I'm sure you probably just want a quick fix and not a suggestion on how to improve your whole way of writing code, so try fixing that simple issue first and see if it resolves the problem.


Thanks alot. I'm new at CLEO and i can't find any information about syntaxis of that language. I thought, that problem was with NOT but i don't know how 'NOT' is writing in CLEO. Now i do.
Go to the top of the page
 
+Quote Post
Reply to this postStart new topic

3 User(s) are reading this topic (3 Guests and 0 Anonymous Users)
0 Members: