プレイ日記
Mr. Birdie birdie1230
How do you use the button element?
0そうだね
プレイ済み
返信[1]
親投稿
Lukas dogcutie
Type this: IF BUTTON()==#button THEN In the (), you can leave it or type a number (You can check help) Where I typed #button, place the button you press (With the # before it) for the thing to work After THEN, place the effect from the code
3そうだね
プレイ済み
返信[2]
親投稿
Oscar PwnageBlock
The BUTTON command returns the press state of all buttons at the moment it was called. What kind of press it was depends on the number you include as the parameter, however, you will probably only use BUTTON() and BUTTON(2), where the empty one returns held down buttons and the one with a 2 returns just pressed buttons. You can also assign BUTTON's return value to a variable for convenience.
2そうだね
プレイ済み
返信[3]
親投稿
Oscar PwnageBlock
You can use BUTTON along with logic gates and constants to build conditionals for your program. You'll want to use the logic gates AND and OR, and the list of constants is this: #A, #B, #X, #Y, #UP, #DOWN, #LEFT, #RIGHT, #L and #R. Each constant corresponds to a button. You cannot use START nor SELECT.
1そうだね
プレイ済み
返信[4]
親投稿
Oscar PwnageBlock
The reason your code doesn't seem to work is because the program checks if the B button is being pressed directly from the program's start. If it's not being pressed it skips the WHILE loop, terminating the program. You can fix this by instead wrapping a simple conditional in another loop. It could look like this... WHILE 1 IF BUTTON() AND #B THEN PRINT "OK" ENDIF WAIT 1 CLS WEND
1そうだね
プレイ済み
返信[5]
親投稿
MathPRG MathProgrammer
Using numbers works too. It can help to shorten your code, however it is easier to remember those constants. They can all be viewed in the HELP menu for the BUTTON() command. For example, 1,2,4, and 8 are UP, DOWN, LEFT, and RIGHT respectively. You can also STATE 'IF BUTTON()==number/constant' instead of using the AND operation. Just some tips to shorten your code ;)
1そうだね
プレイ済み
返信[6]
親投稿
MathPRG MathProgrammer
State wasn't supposed to be capitalized...
0そうだね
プレイ済み
返信[7]
親投稿
MathPRG MathProgrammer
Also you can use IF all in one line, just do 'IF condition THEN commandsToExecute'. Although that's not how it works in higher level languages like C, it at least uses less lines. Multiple-line IF statements are mostly helpful if you've got a ton of commands to execute on one condition.
0そうだね
プレイ済み
返信[8]
親投稿
MathPRG MathProgrammer
Also, in Oscar's sample, it will make an endless loop that will never end unless you click STOP or press Start/Select. You can replace the 1 with a condition you might want to make terminate the program, such as 'WHILE !BUTTON()==16' which will make the program terminate when you press the A button.
0そうだね
プレイ済み
返信[9]
親投稿
Oscar PwnageBlock
While I understand cases in which what you said is useful, some can become shortcomings. Replacing the constants with their actual values decreases the code's readability, specially if you don't have the values memorized. Using == instead of AND means that the button you are comparing must be the only one being pressed. That would mean pressing A would work, but not A and UP.
0そうだね
プレイ済み
返信[10]
親投稿
Oscar PwnageBlock
Also, I used a multi-line IF statement just to make the code a bit more clear. Same goes for the infinite loop, since I didn't want to reuse BUTTON for its example. Those claims are perfectly valid, though.
0そうだね
プレイ済み
返信[11]
親投稿
MathPRG MathProgrammer
Yes, it definitely is better to make your code more readable. What if someone wants to learn what you did with a program? Nice to see which functions do which and stuff. Comments help too but take more space. My arguments are a bit invalid I admit, shorter code doesn't necessarily decrease file size. Even comments need to be stored in memory.
0そうだね
プレイ済み
返信[12]
親投稿
MathPRG MathProgrammer
I don't understand why the AND logic gate is used so much for this command though. Isn't it clearer to ask if BUTTON() is equal to a value?
0そうだね
プレイ済み
返信[13]
親投稿
MathPRG MathProgrammer
Oops, didn't fully take in your last comment. I think I'm a bit tired xD. And while that reasoning for using AND may be helpful, it of course depends on the scenario. If you want A to be a button to, for example, push the gas on a racing game, and B to be the brakes, you'd want it to be A OR B.
0そうだね
プレイ済み
返信[14]
親投稿
MathPRG MathProgrammer
Although why exactly would you want to include any other button in combination with the first as a valid value to carry out a task? It could lead to overlapping functions, as stated earlier. If you wanted A to do one thing and UP another, they would both be usable at the same time, which could lead to errors in the program.
0そうだね
プレイ済み
返信[15]
親投稿
MathPRG MathProgrammer
I guess I'm just a bit picky about my programs lol :P. Besides, the HELP menu is there to describe any command you put the cursor over thoroughly, including all integer values that may be returned and any constants related. If you look in POLYGON's source code, I very rarely used the RGB() command, I replaced RGB(255,0,0) or #RED with -65536 and everything x) I memorized the first 21 powers of 2.
1そうだね
プレイ済み
返信[16]
親投稿
MathPRG MathProgrammer
*I promise without a calculator!* 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152
2そうだね
プレイ済み
返信[17]
親投稿
MathPRG MathProgrammer
I also know a few negative ones. Starting at 2^0 and going down, 1 0.5 0.25 0.125 0.0625 0.03125 0.015625
1そうだね
プレイ済み
返信[18]
親投稿
MathPRG MathProgrammer
One more! The first fifteen digits of π are 3.141592653589793
2そうだね
プレイ済み
返信[19]
親投稿
bill r10l12
is this fun? im thinking about getting it! is it east to use?
1そうだね
未プレイ