Forums

Topic: Petit Computer

Posts 7,261 to 7,280 of 9,620

mystman12

ramstrong wrote:

The answer to that question can fill a very thick book. Or two.

I'd start with state-based automata. Then you can simply do ON state GOTO ... and fill in the details.

Okay, that's pretty much what I was thinking. It seems like it could get pretty confusing though. Well, I'll try my best.

I like makin' games!
Future Pinball games!
Petit Computer games!!
and SmileBASIC games!
Waiting for Kirby Air Ride 2. One day, it will come. One day...

3DS Friend Code: 0259-0292-5888 | Nintendo Network ID: mystman12 | Twitter:

randomous

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:

Math: 92,92
IF: 47,69
ON-GOSUB: 26,52
Array: 52,52

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.

Edited on by randomous

randomous

ramstrong

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!

Edited on by ramstrong

Petit Computer Journal
Old site http://ramstrong.blogspot.com

Let's just call a spade, a spade.

3DS Friend Code: 1091-7596-4855

GraphicGenius

Hey, where'd @Pootrick2 go?

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

TAINT_Zzyex

programmerpro wrote:

Hey, where'd @Pootrick2 go?

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"

Twitter:

randomous

@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.

Edited on by randomous

randomous

InsertPi

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:

RAND PUSH(more/less/null) MAX[max number]=variable slot

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.

3DS Friend Code: 2148-9259-0831 | Nintendo Network ID: IAmAPerson620 | Twitter:

calc84maniac

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.

Edited on by calc84maniac

calc84maniac

InsertPi

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.

3DS Friend Code: 2148-9259-0831 | Nintendo Network ID: IAmAPerson620 | Twitter:

Arn0ld

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

Discostew

Xtremetdifan wrote:

@countdown
Time=12000
Vsync 1
Time=Time-1
If time<=0 goto @death
Pnltype "off"
Pnlstr 0,0,STR$(print time/60)
Goto @countdown

That should do the trick. You don't need to call PNLTYPE each frame, so do it at the beginning before the loop.

Edited on by Discostew

Discostew

3DS Friend Code: 4425-1477-0127 | Nintendo Network ID: Discostew

Arn0ld

Discostew wrote:

Xtremetdifan wrote:

@countdown
Time=12000
Vsync 1
Time=Time-1
If time<=0 goto @death
Pnltype "off"
Pnlstr 0,0,STR$(print time/60)
Goto @countdown

That should do the trick. You don't need to call PNLTYPE each frame, so do it at the beginning before the loop.

Hmm... It returns with syntax error (188,STR$)
I put it before the loop and where you bolded... That returned with
Syntax error (194,STR$)

Botw > OoT

3DS Friend Code: 0748-4970-2550 | Nintendo Network ID: Xjarnold

Pixelrobin

Xtremetdifan wrote:

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.

Edited on by Pixelrobin

Everybody do a chirp. CHIRP.

3DS Friend Code: 3007-9228-5126

Discostew

Xtremetdifan wrote:

Discostew wrote:

Xtremetdifan wrote:

@countdown
Time=12000
Vsync 1
Time=Time-1
If time<=0 goto @death
Pnltype "off"
Pnlstr 0,0,STR$(print time/60)
Goto @countdown

That should do the trick. You don't need to call PNLTYPE each frame, so do it at the beginning before the loop.

Hmm... It returns with syntax error (188,STR$)
I put it before the loop and where you bolded... That returned with
Syntax error (194,STR$)

Oops, forgot to remove the print word in the parentheses. That's what I get for responding on a phone.

Discostew

3DS Friend Code: 4425-1477-0127 | Nintendo Network ID: Discostew

Arn0ld

Bluerobin2 wrote:

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

Malltog

Xtremetdifan wrote:

Bluerobin2 wrote:

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.

How about this?

@LOOP
do stuff here
GOSUB @MORE
GOTO @LOOP

@MORE
do stuff here
RETURN

Malltog

Nintendo Network ID: Malltog

InsertPi

About to release SimpleC v1.2! This is the last production version. Any updates after this will be at you guys' request. CHANGELOG:

Fixed comparison glitch when using WHEN and variables. (example:

WHEN VAR[0]<1 DO{}

will not work)

Changed available variables/strings from 10 to about 300! You can use symbols now! Instead of being restricted to

VAR[0] or STR[1]

you can do ANY character! Such as

VAR[A] or STR[T]

or even:

VAR[┘] or STR[▓]

About to add more than 22 lines! (does 500 sound like enough?)

Updates to syntax of OUT<, INP>, and MATH.

Added OBJCT.SIZ command to change the size of placed objects.

Will release tomorrow!

Edited on by InsertPi

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.

3DS Friend Code: 2148-9259-0831 | Nintendo Network ID: IAmAPerson620 | Twitter:

ShadowGame

@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...

ShadowGame

LeviCelJir

I dunno why but shooting in my games being bad :/. Its moving the character with the bullet
heres some of the code:

@MOVE
B=BUTTON()
IF B AND 1 THEN GOSUB @UP
IF B AND 2 THEN GOSUB @DOWN
IF B AND 32 THEN GOSUB @ SHOOT
IF SHOOT==1 THEN GOSUB @MOVEBULLET
GOTO @MOVE

@UP
VSYNC 1
SPSET 0,0,0,0,0,0
SPSCALE 0,200,0
SPHOME 0,0,0
SPSET 1,1,0,0,0,0
SPSCALE 1,200,0
SPHOME 1,-8,0
SPOFS 0,X,Y,0
SPOFS 1,X,Y,0
Y=Y-1
RETURN

@DOWN
VSYNC 1
SPSET 0,0,0,0,0,0
SPSCALE 0,200,0
SPHOME 0,0,0
SPSET 1,1,0,0,0,0
SPSCALE 1,200,0
SPHOME 1,-8,0
SPOFS 0,X,Y,0
SPOFS 1,X,Y,0
Y=Y+1
RETURN

@SHOOT
SHOOT=1
RETURN

@MOVEBULLET
SPSET 3,2,0,0,0,0
SPOFS 3,X,Y,0
X=X+1
IF X>200 THEN SPCLR 3
RETURN

why is it doing this? can anybody fix this code so it works?

Hi I'm Levi and I like Bloopys :^)

Gimmemorecoinz

Discostew wrote:

bluerobin2 wrote:

@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

Please login or sign up to reply to this topic