Forums

Topic: Petit Computer

Posts 561 to 580 of 9,620

Cocobanana

How do you set it with dim?

Cocobanana

portealmario

Don't you just write "DIM F(Q)"?

meng 😐
3ds friend code:1762-2769-7142

Cocobanana

I tried that, but i get this error:
Duplicate definition (11, DIM)

Cocobanana

ramstrong

Cocobanana wrote:

Thanks!

Also, i got this error:
Subscript out of range (11)

My code is:
F(Q)=0

Whats wrong with that?

You need to ask better questions than that because there is nothing wrong with that statement. The error lies somewhere else. It is important that you write the shortest code that still demonstrate the problem. You need to figure out what the problem is and write a sample program that duplicates the same problem. If you have Duplicate Definition Error, you should write this program:
DIM A$[10]
and run it twice. Why did it fail the second time? DIM defines the variable. You cannot redefine variables here. There are different situations that can take advantage of previously defined variables, so this isn't an error. You need to figure out a way around it.

Don't take it the wrong way, but I think you should familiarize yourself with Petit Computer and type in other people's program and see how they work. Otherwise, we'd be porting your program for you, and who knows how long that will take? We're here to help, not do your homework for you. You need to have some initiative yourself.

Try to learn something new everyday, and write a small program to demonstrate your learning. Share if you do. We can use more tutorial pages!

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

Let's just call a spade, a spade.

3DS Friend Code: 1091-7596-4855

Cocobanana

Im sorry, its just frustrating when it doesnt work.

One more question, then im done..
Here is my full coding for a dice simulator.
LOCATE 10,1:? "Dice"
PRINT:PRINT:PRINT
DIM F(12)
PRINT "THIS PROGRAM SIMULATES THE ROLLING OF A"
PRINT "PAIR OF DICE."
PRINT "YOU ENTER THE NUMBER OF TIMES YOU WANT THE COMPUTER TO"
PRINT "'ROLL' THE DICE. WATCH OUT, VERY LARGE NUMBERS TAKE"
PRINT "A LONG TIME. IN PARTICULAR, NUMBERS OVER 5000."
FOR Q=1 TO 12
F(Q)=0
NEXT Q
PRINT:PRINT "HOW MANY ROLLS";
INPUT X
FOR S=1 TO X
A=INT(6*RND(1)+1)
B=INT(6*RND(1)+1)
R=A+B
F(R)=F(R)+1
NEXT S
PRINT
PRINT "TOTAL SPOTS","NUMBER OF TIMES"
FOR V=2 TO 12
PRINT V,F(V)
NEXT V
PRINT
PRINT:PRINT "TRY AGAIN";
INPUT Z$
IF Z$="YES" THEN 80
END

But it doesnt work:/
I tried dim F(Q), but it says duplicate definition.

Cocobanana

ramstrong

Eh, whatever happens to the SIMPLEST, SHORTEST code that demonstrate the problem? Sigh.
DIM F(12) means array index is 0..11 so
FOR Q=0 TO 11

You don't need letter after NEXT. So
NEXT
not NEXT S

You need to fix FOR V=2 TO 12 because the array index is insufficient.

Comparison is ==, so
IF Z$=="YES" GOTO @LABEL
There is no line number, so THEN 80 isn't valid.

You need to CLEAR the variables. Put this command on first line.

Randomization works differently. You need to read the help file
A=RND(6)+1

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

Let's just call a spade, a spade.

3DS Friend Code: 1091-7596-4855

ramstrong

CLS:CLEAR
DIM D[13]
INPUT "NUMBER OF DICE ROLLS";N
FOR I=1 TO N
@ROLL
R=RND(6)+RND(6)+2
IF R<2 GOTO @ROLL
D[R]=D[R]+1
NEXT
FOR I=2 TO 12
?I,D[I]
NEXT

Edit:
Don't need @ROLL because randomization is +2, but I figure I'd show you how to do LABEL and GOTO.

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

Cocobanana

Thanks so much!

It doesnt work with the First line, but it works if you take it out.

Edit: how do you get the QR code?

Edited on by Cocobanana

Cocobanana

triotip

Can someone help me i'm trying to use sphitsp like this IF SPHITSP (1,0) THEN GOSUB @STORE and it won't work (it is in a loop) all that happens is that the store opens as long as the store sprite is on screen.

triotip

ramstrong

triotip wrote:

Can someone help me i'm trying to use sphitsp like this IF SPHITSP (1,0) THEN GOSUB @STORE and it won't work (it is in a loop) all that happens is that the store opens as long as the store sprite is on screen.

You don't make it easy for us to help you, do you? Did not Cocobanana just now had trouble getting his question answered because he didn't give out enough info? From now on, unless the question is well formed, I don't want to answer. What kind of questions are good ones? Petit Tutorial Forum post#9.

In your case, though, I'd say that the store opens only when the sprite in on screen because you did not supply a Status/Flag variable that specify the store should be open when the sprite is off screen. That is:
STORE=OPEN if SPRITE=HIT
when what you want is
SHOULDOPEN=TRUE if SPRITE=HIT
STORE=OPEN if SHOULDOPEN=TRUE

That's just pseudocode. You need to do the programming yourself. You also need to specify the condition when the store should close. Be careful, you don't want to close the store when the sprite isn't hit!

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

Let's just call a spade, a spade.

3DS Friend Code: 1091-7596-4855

triotip

okay let me reform my question because your answer didn't fix my problem.
i have a sprite in the middle of the screen that represents your character and another sprite that represents the store.
i want the store to open when your sprite hits the store sprite.

triotip

Cocobanana

I never knew it was bad to ask a question,

Cocobanana

ramstrong

Cocobanana wrote:

I never knew it was bad to ask a question,

Depends on the question. Did you read the tutorial post? Here's an example:

You know how PRINT statement works, right? What if there's somebody who ask help like this: "How do you use PRINT?", following your answer with "It doesn't work."

Here's what I want to see:

When I see the words "I don't understand ..." it'd better be followed by "These are the things I tried in order to understand it."

See the difference?

Please,please, please read the tutorial post. It will make life much easier for everybody.

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

Let's just call a spade, a spade.

3DS Friend Code: 1091-7596-4855

Cocobanana

Im sorry, ill post it that way next time.

And i have not read the tutorial, i thought i already knew how to use this lol.

Cocobanana

portealmario

Is there a command that stops the computer from going through coding and waits for the user to press any key to continue(like the "sleep" command in other BASIC languages)?

meng 😐
3ds friend code:1762-2769-7142

ramstrong

Morphtroid wrote:

I won't be able to use Petit Computer for a while until I get a new stylus and screen protector

Keep programming for me, you all.

I'm curious of how well can people copying code from text as opposed to just scan QR code. So, this will come only as source code, no QR. Let's see how well you can copy this, and hopefully understand it. I won't be explaining anything. The source code tells all!

Major bragging rights to the first person who can change P[] array to meaningful numbers. Except for Morphtroid, who can do this in his sleep!
If you have problem, you may ask for explanation, but make sure to do your homework and show your analysis of the problem, with your potential solution.

PS: I did this in 2 hours pecking at the screen with the stylus! How far can you go? Keep pushing!

CLS:CLEAR
DIM P[16]
GOSUB @INIT
GOSUB @DISP

@LOOP
GOSUB @PANE
GOSUB @MOVE
IF G$==P$ GOTO @END
GOTO @LOOP

@END
BEEP 7:LOCATE 18,18:?"WIN!"
FOR I=1 TO 1:VSYNC 1:I=BUTTON(3):NEXT
END

@MOVE
FOR I=1 TO 1:VSYNC 1:B=BUTTON(3):I=B:NEXT
BEEP 66
IF B AND 32 THEN G$=SUBST$(G$,CY*16+CX,1,"0")
IF B AND 16 THEN G$=SUBST$(G$,CY*16+CX,1,"1")
IF B AND 1 THEN CY=CY+15
IF B AND 2 THEN CY=CY+1
IF B AND 4 THEN CX=CX+15
IF B AND 8 THEN CX=CX+1
CX=CX%16:CY=CY%16
SPOFS 1,CX*8,CY*8
RETURN

@PANE
FOR I=0 TO 15:FOR J=0 TO 15
LOCATE J,I
IF "0"==MID$(G$,I*16+J,1) THEN ?CHR$(32) ELSE ?CHR$(224)
NEXT:NEXT
RETURN

@DISP
CLS
FOR I=0 TO 255 STEP 16
H$="":C=0
FOR J=0 TO 15
IF "1"==MID$(P$,I+J,1) THEN C=C+1
IF "0"==MID$(p$,I+J,1) THEN IF C THEN H$=H$+STR$(C):C=0
NEXT
IF C THEN H$=H$+STR$(C)
LOCATE 17,I/16:?H$
NEXT

FOR I=0 TO 15
H$="":C=0
FOR J=0 TO 15
IF "1"==MID$(P$,I+(J*16),1) THEN C=C+1
IF "0"==MID$(p$,I+(J*16),1) THEN IF C THEN H$=H$+STR$(C):C=0
NEXT
IF C THEN H$=H$+STR$(C)
FOR J=0 TO LEN(H$)
LOCATE I,16+J:?MID$(H$,J,1);
NEXT
NEXT
RETURN

@INIT
P[0]=2016
P[1]=14364
P[2]=16770
P[3]=33729
P[4]=35793
P[5]=40377
P[6]=24186
P[7]=19506
P[8]=12300
P[9]=21066
P[10]=18834
P[11]=38505
P[12]=44085
P[13]=25638
P[14]=24582
P[15]=4104

FOR I=0 TO 15
V=P[I]:T$=""
FOR J=0 TO 15
T$=STR$(V%2)+T$:V=FLOOR(V/2)
NEXT
P$=P$+T$
NEXT

G$="0"*LEN(P$)

SPSET 1,156,0,0,0,0,16,16
SPANIM 1,4,15
SPSCALE 1,50
CX=0:CY=0
RETURN

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

Let's just call a spade, a spade.

3DS Friend Code: 1091-7596-4855

Please login or sign up to reply to this topic