OK, here are the results. The first number is the time spent when no buttons were pressed. The second one is the time spent when two directions were pressed:
What does this mean? Apart from me messing up on my own test, it means the following:
-Assignments are expensive, but @Discostew's been telling you all that for ages lol
-Array is the way to go for a consistent experience.
-If variable speed is OK, and you somehow need extra performance when no buttons are pressed, go for the ON-GOSUB method
-Math and IF statements aren't as useful unless you're tight for code size or you want readability.
So ON-GOSUB isn't as fast as I once said it was, but its still the lower bound for the set.... even if its implementation is gross and has way too much repetition. The array method that @ramstrong described (yes, I made sure it was right this time before posting the results) is extremely readable from the standpoint of the loop, but rather obfuscated when you look at what you have to do to get it to work (an extra data section full of seemingly random 0's, 1's, and -1's). These two are your best bets for speed, and are useful in different situations. Really, it seems like the array method is the best (even though ON-GOSUB beats it when it's sitting around), because I'd take consistency over variability in speed any day. Thanks @ramstrong, I had initially come up with the very same idea, but I thought array accesses would take too long.
So yeah, you're never actually going to need so much speed that you'd need to change the way you do it... unless you're @Discostew. As long as the method you pick is the one you prefer and the one you can read the best, go for it! I personally find the math method easiest to read, so I stubbornly use it even though it's the slowest of the bunch 100% of the time.
Thanks randomous. Yeah, array variable assignment does take a long but stable time. I figured that as long as I shuffle the init function somewhere out of sight, it should be OK from readability point of view. Thanks for checking it out.
Edit: Hey, I think this should go up on Tutorial thread. Good stuff here!
If Facebook, Myspace, Twitter, Instagram, and Snapchat were all destroyed, 90% of teens would go insane. If you're one of the 10% that would be laughing at them, copy & paste this into your signature and hope it happens. Wait was that just a joke?
3DS Friend Code: 1478-3545-5136 | Nintendo Network ID: GreatGamer123
Sooooommmme weeeeere ovvvvvver the raaIIIIINNNNBoooow! No, not realy. I do believe he has
kay-rat-aye on thursday. And now to be on topic, there is one problem with my game, i have
input name$
print —————————
print|"; name$; " |
print—————————
the name dosnt fill the box right. how could i make it add space if name is to short?
"Did somebody say Aincrad?"
"No, go back to your own game!"
"awwww"
"And make out with Asuna."
"Aww-I mean YAY"
@TAINT_Zzyex Let's say you want the name to be exactly 8 characters. I'd do this:
namePadded$ = LEFT$(name$ + " ", 8)
Then use namePadded$ when you need extra space, and name$ when you don't. That " " contains 8 spaces (or it would if it showed them all). If you wanted the name to be 16 characters, just use a " " with 16 spaces instead, and replace the 8 in LEFT with 16.
Ugh. I need to make a random number generator that doesn't randomly generate random numbers. AKA I need 2 random number generators: one that has a higher probability of choosing higher numbers by 50%, and one that does the same but with lower numbers. Any ideas? For SimpleC, I'm making a RAND commad:
If Facebook, Myspace, Twitter, Instagram, and Snapchat were all destroyed, 90% of teens would go insane. If you're one of the 10% that would be laughing at them, copy & paste this into your signature and hope it happens.
Here's an even faster array method (I'm getting like 45 cycles with this). Initialize like so:
DIM DX(2048)
DIM DY(2048)
FOR B=0 TO 2047
DX(B)=(B/8 AND 1)-(B/4 AND 1)
DY(B)=(B/2 AND 1)-(B AND 1)
NEXT
Then, handle movement with:
X=X+DX(BUTTON())
Y=Y+DY(BUTTON())
Edit: Fixed array sizes, forgot that BUTTON() values can go up to 2047.
Nevermind about the generator! I made one! On average, the randomized numbers are greater than half the number 75% of the time.
If Facebook, Myspace, Twitter, Instagram, and Snapchat were all destroyed, 90% of teens would go insane. If you're one of the 10% that would be laughing at them, copy & paste this into your signature and hope it happens.
Does anyone know what's wrong with this code? It's a time limit displayed on the touch screen for the sonic game I'm "making" as I slowly learn smile basic. @countdown
Time=12000
Vsync 1
Time=Time-1
If time<=0 goto @death
Pnltype "off"
Pnlstr 0,0,"print time/60"
Goto @countdown
It prints print time instead of the actual time counting down and taking away the quotation marks end in a missing operand.
Btw is it possible to have multiple gotos at once?
Sorry for so many questions I know this looks pretty stupid if you are advanced with smile basic.
Botw > OoT
3DS Friend Code: 0748-4970-2550 | Nintendo Network ID: Xjarnold
Does anyone know what's wrong with this code? It's a time limit displayed on the touch screen for the sonic game I'm "making" as I slowly learn smile basic. @countdown
Time=12000
Vsync 1
Time=Time-1
If time<=0 goto @death
Pnltype "off"
Pnlstr 0,0,"print time/60"
Goto @countdown
It prints print time instead of the actual time counting down and taking away the quotation marks end in a missing operand.
Btw is it possible to have multiple gotos at once?
Sorry for so many questions I know this looks pretty stupid if you are advanced with smile basic.
PNLTYPE "OFF"
TIME=12000 @COUNTDOWN
VSYNC 1
TIME = TIME - 1
PNLSTR 0,0," "
PNLSTR 0,0,STR$(TIME/60)
IF TIME<=0 THEN GOTO @DEATH
GOTO @COUNTDOWN
First of all, you have the Pnlstring wrong. Then, you're resetting the time every loop. Plus you're wasting cpu time by clearing the bottom screen every time. AND you're forgetting to clear the space before printing a new time. You need this because the numbers go down and when they get into the tens, it'll look weird. The above code should fix this. Good luck!
As for your GOTO question, yes you can. And GOSUBS too. But don't use too many.
PNLTYPE "OFF"
TIME=12000 @COUNTDOWN
VSYNC 1
TIME = TIME - 1
PNLSTR 0,0," "
PNLSTR 0,0,STR$(TIME/60)
IF TIME<=0 THEN GOTO @DEATH
GOTO @COUNTDOWN
First of all, you have the Pnlstring wrong. Then, you're resetting the time every loop. Plus you're wasting cpu time by clearing the bottom screen every time. AND you're forgetting to clear the space before printing a new time. You need this because the numbers go down and when they get into the tens, it'll look weird. The above code should fix this. Good luck!
As for your GOTO question, yes you can. And GOSUBS too. But don't use too many.
Wow thanks Bluerobin2! It works! And thanks for trying to help @discostew! However I think I was unclear with my gotos question. You see how this one loops itself to keep the time going? Well I was using a similar loop for the controls(I know how to move,animate,etc sprites) but when you have @controls
If button() and 4 then x=x-3:then spamin Yada Yada Yada repeat for moving right...
Goto @controls
I was asking if it were possible to have both going at once as gosubs run out of memory and which ever is coded first (controls or countdown) is used while the other is omitted.
Botw > OoT
3DS Friend Code: 0748-4970-2550 | Nintendo Network ID: Xjarnold
PNLTYPE "OFF"
TIME=12000 @COUNTDOWN
VSYNC 1
TIME = TIME - 1
PNLSTR 0,0," "
PNLSTR 0,0,STR$(TIME/60)
IF TIME<=0 THEN GOTO @DEATH
GOTO @COUNTDOWN
First of all, you have the Pnlstring wrong. Then, you're resetting the time every loop. Plus you're wasting cpu time by clearing the bottom screen every time. AND you're forgetting to clear the space before printing a new time. You need this because the numbers go down and when they get into the tens, it'll look weird. The above code should fix this. Good luck!
As for your GOTO question, yes you can. And GOSUBS too. But don't use too many.
Wow thanks Bluerobin2! It works! And thanks for trying to help @discostew! However I think I was unclear with my gotos question. You see how this one loops itself to keep the time going? Well I was using a similar loop for the controls(I know how to move,animate,etc sprites) but when you have @controls
If button() and 4 then x=x-3:then spamin Yada Yada Yada repeat for moving right...
Goto @controls
I was asking if it were possible to have both going at once as gosubs run out of memory and which ever is coded first (controls or countdown) is used while the other is omitted.
If Facebook, Myspace, Twitter, Instagram, and Snapchat were all destroyed, 90% of teens would go insane. If you're one of the 10% that would be laughing at them, copy & paste this into your signature and hope it happens.
@IAmAPerson
Cool, a new version!!
Can you please, please copy the tutorial for simple c in the wiki or in this Thread?
Please!!
I cant Download it because i only have an iPod and a 3DS
so i cant Download it...
@Discostew so that is how you do it. thanks! But another question from me this time, can you save multiple variables in a single MEM?
You can as strings (in which your numbers get converted using STR$), but what you need is some method to separate them within the 256 character MEM$ string. Assume you have "/" as your delimiting character. You can then concatenate strings together, and then save them as MEM files. When you want to load them from MEM, you would need a parser such as the following...
Use INSTR to find the delimiting character, and get its position
Use LEFT$ to grab the left portion of the string containing the first variable, and set the string as the remaining part using RIGHT$, both excluding the "/" character found using INSTR
The string after being set with RIGHT$ now excludes the first variable, so the 2nd variable now becomes the first in the full string. Repeat the above 2 steps to grab all remaining variables. Convert number strings with VAL.
CLEAR
LOAD "MEM:MYSTR",FALSE
DIM STRARR$(257)
NUMSTR=0 @GRABNEXT
SPOS=INSTR(MEM$,"/")
IF SPOS==-1 GOTO @FINISHEXT
STRARR$(NUMSTR)=LEFT$(MEM$,SPOS)
MEM$=RIGHT$(MEM$,LEN(MEM$)-SPOS-1)
NUMSTR=NUMSTR+1
GOTO @GRABNEXT @FINISHEXT
STRARR$(NUMSTR)=MEM$
NUMSTR=NUMSTR+1
FOR I=0 TO NUMSTR-1
PRINT STRARR$(I)
NEXT
If MEM$ contains "This/is/a/string", then the output would be
This
is
a
string
If MEM$ contains "This/is not a/string", then the output would be
This
is not a
string
WARNING:
I have not tested the above code, so let me know if problems arise.
This was posted a while ago wasn't it? And another solution was posted before to...
I thought that INSTR auto increased to the next "token" it found. I was trying to write something similiar and then what happened to me was that I ended up with this when I printed BB=instr$(X$, ",") with comas as the seperator in a for loop
2
2
2
2
2
2
2
2
2
2
that was pretty well the output
it got stuck on position 2.
Urgh and I was having issues with trimming the string properly.
thanks for this solution discostew.. though I feel kind of stupid that I couldn't get something like this to work without help or reading a reference I thought I was better at coding than this!! x.x it's because I didn't quite know how it all worked -.-" stupid ptc is stupid sometimes.
Got a project? PM ME on here!
Youtube: lostkitty64x
Want help with coding? PM ME! PM ME PM ME!! XD
FC: WIll post later.
Systems I own: ds lite, 3DS, PC/gaming, steam platform. I play alot of games. Just ask ! Minecraft anyone? :D
Forums
Topic: Petit Computer
Posts 7,261 to 7,280 of 9,620
Please login or sign up to reply to this topic