Author Topic: Where's the mistake?  (Read 5927 times)

0 Members and 1 Guest are viewing this topic.

Offline p2

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 849
  • Rating: +51/-11
  • I'm back :)
    • View Profile
Where's the mistake?
« on: June 22, 2011, 09:11:22 am »
Hi everyone :) This is the brother of p2... Im called p1  ;)
This morning, my brother came to me and asked me for helping him at programming a BASIC program where a line of length 10 turns around till it points on a position on the screen marked with a single pixel. I then had the idea to not letting the "snake" turn around but walking a curve. My brother didnt want to program it, so I sat down and did it. This is the result... but it doest do what i want it to do: I want it to directly walk to the dot, but not like going on a linear path: it has to walk on a curve (like a car has to), till facing the aim, and then walking towards it. As soon as it gets in a defined near to the dot, this is teleported to another position on the screen. The snake turns a round till the point is in its direction and then walks to it again.
*insert supercool signature*

Ashbad

  • Guest
Re: Where's the mistake?
« Reply #1 on: June 22, 2011, 09:15:14 am »
Welcome, P2's brother :) you should make your own forum account!  ;D

I can't look at the program like this (can't open .8xp programs on my iPad), but Im sure others will be glad to help.

Offline Compynerd255

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +53/-4
  • Betafreak Games
    • View Profile
    • Betafreak Games
Re: Where's the mistake?
« Reply #2 on: June 22, 2011, 10:40:04 am »
Welcome, P2's brother :) you should make your own forum account!  ;D

I can't look at the program like this (can't open .8xp programs on my iPad), but Im sure others will be glad to help.
I second the welcome. :)

A good way for people to easily see the code is to go onto an online code editor such as Sourcecoder to convert the program to plain text, then copy this text inside [code][/code] tags.
« Last Edit: June 22, 2011, 10:40:17 am by Compynerd255 »
The Slime: On Hold, preparing to add dynamic tiles

Axe Eitrix: DONE

Betafreak Games: Fun filled games for XBox and PC. Check it out at http://www.betafreak.com



Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: Where's the mistake?
« Reply #3 on: June 22, 2011, 11:06:50 am »
I used sourcecoder, and added indents, tidied the code up slightly (mostly adding newlines):

Code: [Select]
0→Xmin:1→ΔX
0→Ymin:1→ΔY
ClrDraw
FnOff :AxesOff:GridOff:Func:CoordOff:LabelOff:ExprOff:Full:Degree:a+bi
22→dim(∟SCHL1
2→B
1→∟SCHL1(1):1→∟SCHL1(2)
randInt(4,90)→∟SCHL1(21)
randInt(4,60)→∟SCHL1(22)

While ∟SCHL1(B-1)≠∟SCHL1(21) or ∟SCHL1(B)≠∟SCHL1(22)
    Pt-Change(∟SCHL1(21),∟SCHL1(22)
    For(A,2,20,2)
        Pt-On(round(∟SCHL1(A-1)),round(∟SCHL1(A)
    End

    tan-1((∟SCHL1(B-1)-∟SCHL1(B+1-20(B=20)))/(∟SCHL1(B)-∟SCHL1(B+2-20(B=20))))→C
    tan-1((∟SCHL1(21)-∟SCHL1(B-1))/(∟SCHL1(22)-∟SCHL1(B)))→D

    If abs(D-C)<20
    Then
        (C+D)/2→E
    Else
        (C+40((D-C)>0)-20)→E
    End

    If (√((∟SCHL1(21)-∟SCHL1(B-1))2+(∟SCHL1(22)-∟SCHL1(B))2))<5
    Then
        randInt(4,90)→∟SCHL1(21)
        randInt(4,60)→∟SCHL1(22)
    End

    Pt-Off(∟SCHL1(B-3+20(B=2)),∟SCHL1(B-2+20(B=2)))
    ∟SCHL1(B-1)+cos(E)→∟SCHL1(B-3+20(B=2))
    ∟SCHL1(B)+sin((E)→∟SCHL1(B-2+20(B=2))
    B-2→B
    If B=0:20→B
    Text(1,85,round(C,0
    Text(7,85,round(D,0
    Text(13,85,round(E,0
End
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline Compynerd255

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +53/-4
  • Betafreak Games
    • View Profile
    • Betafreak Games
Re: Where's the mistake?
« Reply #4 on: June 22, 2011, 02:13:38 pm »
I can't really tell what this code is supposed to do, but I did notice a few things:
  • round always needs two arguments: the number and the decimal place. You can't omit the second one.
  • Always initialize all of your variables at the beginning of your program. It seems as if you only initialize B and LSCHL1
  • While ∟SCHL1(B-1)≠∟SCHL1(21) or ∟SCHL1(B)≠∟SCHL1(22) won't just trigger when the point collides. It will also hit if it hits the same row or column.
Other than that, good start!
The Slime: On Hold, preparing to add dynamic tiles

Axe Eitrix: DONE

Betafreak Games: Fun filled games for XBox and PC. Check it out at http://www.betafreak.com



Offline Scipi

  • Omni Kitten Meow~ =^ω^=
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1547
  • Rating: +192/-3
  • Meow :3
    • View Profile
    • ScipiSoftware
Re: Where's the mistake?
« Reply #5 on: June 22, 2011, 02:23:21 pm »
Quote
Always initialize all of your variables at the beginning of your program. It seems as if you only initialize B and LSCHL1
All the variables used are initialized properly, just they are within the program body.

I tried to see what could be the problem, but I can't figure out where the code that gives the curve to move on is. I also don't see where the code that has it move in a straight line once it points to the dot is.

Other than that, this completely blew my mind! O.O I agree with Compy, a very good start. ;D

Imma Cat! =^_^= :3 (It's an emoticon now!)
Spoiler For Things I find interesting:
Spoiler For AI Programming:
Spoiler For Shameless advertising:

Spoiler For OldSig:





Spoiler For IMPORTANT NEWS!:
Late last night, Quebec was invaded by a group calling themselves, "Omnimaga". Not much is known about these mysterious people except that they all carried calculators of some kind and they all seemed to converge on one house in particular. Experts estimate that the combined power of their fabled calculators is greater than all the worlds super computers put together. The group seems to be holding out in the home of a certain DJ_O, who the Omnimagians claim to be their founder. Such power has put the world at a standstill with everyone waiting to see what the Omnimagians will do...

Wait... This just in, the Omnimagians have sent the UN a list of demands that must be met or else the world will be "submitted to the wrath of Netham45's Lobster Army". Such demands include >9001 crates of peanuts, sacrificial blue lobsters, and a wide assortment of cherry flavored items. With such computing power stored in the hands of such people, we can only hope these demands are met.

In the wake of these events, we can only ask, Why? Why do these people make these demands, what caused them to gather, and what are their future plans...

Offline p2

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 849
  • Rating: +51/-11
  • I'm back :)
    • View Profile
Re: Where's the mistake?
« Reply #6 on: June 23, 2011, 08:58:28 am »
p2:
My brother has told me a few things:
every step of the "snake" the angel betwen the point and the "snake" will be cut in half.
The problem is that the "Snake" walks a courve, but not to the point, it walks from past.
The "snake" is a list with a dim of 10.
It always deletes the last point and adds a new point in front of the list.


This
Code: [Select]
0→Xmin:1→ΔX
0→Ymin:1→ΔY
ClrDraw
FnOff :AxesOff:GridOff:Func:CoordOff:LabelOff:ExprOff:Full:Degree:a+bi
22→dim(∟SCHL1
2→B
1→∟SCHL1(1):1→∟SCHL1(2)
randInt(4,90)→∟SCHL1(21)
randInt(4,60)→∟SCHL1(22)

While ∟SCHL1(B-1)≠∟SCHL1(21) or ∟SCHL1(B)≠∟SCHL1(22)
    Pt-Change(∟SCHL1(21),∟SCHL1(22)
    For(A,2,20,2)
        Pt-On(round(∟SCHL1(A-1)),round(∟SCHL1(A)[b],0[/b]
    End

    tan-1((∟SCHL1(B-1)-∟SCHL1(B+1-20(B=20)))/(∟SCHL1(B)-∟SCHL1(B+2-20(B=20))))→C
    tan-1((∟SCHL1(21)-∟SCHL1(B-1))/(∟SCHL1(22)-∟SCHL1(B)))→D

    If abs(D-C)<20
    Then
        (C+D)/2→E
    Else
        (C+40((D-C)>0)-20)→E
    End

    If (√((∟SCHL1(21)-∟SCHL1(B-1))[b]^2[/b]+(∟SCHL1(22)-∟SCHL1(B))2))<5        //It's [b]^2[/b] and not just [b]2[/b]
    Then
        randInt(4,90)→∟SCHL1(21)
        randInt(4,60)→∟SCHL1(22)
    End

    Pt-Off(∟SCHL1(B-3+20(B=2)),∟SCHL1(B-2+20(B=2)))
    ∟SCHL1(B-1)+cos(E)→∟SCHL1(B-3+20(B=2))
    ∟SCHL1(B)+sin((E)→∟SCHL1(B-2+20(B=2))
    B-2→B
    If B=0:20→B
    Text(1,85,round(C,0
    Text(7,85,round(D,0
    Text(13,85,round(E,0
End






This is the code of my program:
Code: [Select]
:randInt(0,94)→X
:randInt(0,62)→Y
:randInt(0,94)→V
:randInt(0,62)→W
:randInt(0,94)→A
:randInt(0,62)→B
:7→V
:31→W
:32→T
:31→U
:11→J
:2→n
:While 1
:Pt-Off(Z,K
:Pt-On(V,W
:Pt-Off(R,S
:Pt-On(X,Y
:Pt-Off(C,D
:Pt-On(A,B
:Line(Z,K,R,S,0
:Line(V,W,X,Y
:√((X-V)²+(Y-W)²)→θ
:√((A-X)²+(B-Y)²)→N
:V→Z
:W→K
:X→R
:Y→S
:A→C
:B→D
:
:
:If N≤5
:Then
:randInt(0,94)→A
:randInt(0,62)→B
:End
:
:
:If J<9
:Then
:If V>X:V+.5abs(V-X)/θ→V
:If V<X:V-.5abs(V-X)/θ→V
:If W>Y:W+.5abs(W-Y)/θ→W
:If W<Y:W-.5abs(W-Y)/θ→W
:End
:
:
:If J>10
:Then
:If V>X:V-.5abs(V-X)/θ→V
:If V<X:V+.5abs(V-X)/θ→V
:If W>Y:W-.5abs(W-Y)/θ→W
:If W<Y:W+.5abs(W-Y)/θ→W
:
:End
:
:If N>5
:Then
:
:If X>A:X-.5abs(X-A)/N→X
:If X<A:X+.5abs(X-A)/N→X
:If Y>B:Y-.5abs(Y-B)/N→Y
:If Y<B:Y+.5abs(Y-B)/N→Y
:
:End
:
:
:
:√((V-X)²+(W-Y)²)→J
:
:
:End
It always sets a point where the snake will walk to.
I just wanted a line with a lenth of ten which walks to the point.

p1 wanted the Line/snake not to spin, but to walk a courve.
*insert supercool signature*