English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. AMOS

 
 
Thread Tools
Old 30 August 2018, 21:35   #1
Predseda
Puttymoon inhabitant
 
Predseda's Avatar
 
Join Date: Mar 2007
Location: Tromaville
Age: 46
Posts: 7,538
Send a message via ICQ to Predseda
AMAL animation string

My program starts like this:

Setting up the screen and then:
Code:
Channel 3 to Bob 3
Shared A,B,C,D,E,F
A=Rnd(200): B=Rnd(100)
Set Bob 1,,,
Set Bob 2,,,
Set Bob 3,,,
Bob 1,A,B,1
Here Bob 1 is displayed on the random position on the screen.
.
.
.
.
Then I have some condition inside the loop for a procedure, that is called when LMB is pressed

Code:
Do
If Mouse Key=1 Then MOVEMENT
Loop
.
.
.
Now the program jumps to execute a procedure. Procedure looks like this:

Code:
Procedure MOVEMENT
C=X Mouse-128
D=Y Mouse-42
E=C-A
F=B-D
Bob 3, A, B, 2
(At this moment Bob 3 is displayed on the position of Bob 1. I would like it move to the position of the mouse cursor when I clicked LMB. Mouse position at this moment is C,D and the distance of the Bob 3 from the C,D is E horizontally, F vertically)

Code:
A$="S: Move E,F,100; Jump S"
Amal 3, A$
Amal On 3
End Proc
And now my problem. When I click LMB, Bob 3 is displayed where it should be, but the program is terminated with

Quote:
Syntax Error in animation string
Amal 3, A$
My opinion is that Move in animation string doesn't accept variable values E,F and expects numbers instead. It works when I put some numerical constants instead of letters there, for example Move 50,30,100. What can I do?
Predseda is offline  
Old 30 August 2018, 21:54   #2
Epo
Users Awaiting Email Confirmation
 
Join Date: Aug 2018
Location: Country
Posts: 38
It doesn't work that way, you can't use AMOS variable with AMAL just like that. In order to use it in AMAL you have to use Amreg command to 'pass' it there (or read from). Please read in the doc or look for an exaple code because it's not that simply as BASIC syntax.

Update: Alright, I wasn't going to do it because I'm moving to a new apartment and I don't have much time now but... it was a challenge I often take up ;-). Firstly, your solution simply can not work because you mistake X and Y coordinates with how many pixels command Move should move a Bob. What's more, Move will not move a Bob to a position you think, it will move it by X and Y pixels adding to its actual position. For example if a Bob is on X=300, Y=100 and you send to AMAL "Move X=(your X Mouse coordinates), Y=(your Y Mouse coordinates) it will add to 300 the value of your X Mouse and will do the same with Y. Simply your Bob will fly out of the screen in opposite to your desire direction.

Here is the working code (you may adapt it to your needs):

Code:
Curs Off 
Channel 3 To Bob 3

X=160 : Y=100
Bob 3,X,Y,2
Amreg(Asc("X")-65)=X : Rem // Pass the starting coordinate X to the Register X
Amreg(Asc("Y")-65)=Y : Rem // Pass the starting coordinate Y to the Register Y

Do 
   If Mouse Key=1 Then MOVEMENT
Loop 

Procedure MOVEMENT

   DESTX=X Mouse-128 : Rem       // Read the value where the mouse X clicked
   DESTY=Y Mouse-50 : Rem        // Read the value where the mouse Y clicked 
   ACTX=Amreg(Asc("X")-65) : Rem // Read the actual Bob position X
   ACTY=Amreg(Asc("Y")-65) : Rem // Read the actual Bob position Y

   XDIST=DESTX-ACTX : Rem        // Take the X distance between actual Bob coordinates and the destination 
   YDIST=DESTY-ACTY : Rem        // Take the Y distance between actual Bob coordinates and the destination 
   R#=Sqr(XDIST^2+YDIST^2) : Rem // Callculate stright line 

   For I=1 To R#

      '// You have to handle division by 0 in RX/RY by your own  
      RX=ACTX+(I/R#)*(XDIST) : Rem // Calculate next step X 
      RY=ACTY+(I/R#)*(YDIST) : Rem // Calculate next step Y 
      Amreg(Asc("X")-65)=RX : Rem  // Pass it to the Register X
      Amreg(Asc("Y")-65)=RY : Rem  // Pass it to the Register Y

      A$="Let X=RX; Let Y=RY"

      Amal 3,A$
      Amal On 3

      X=Amreg(Asc("X")-65)
      Y=Amreg(Asc("Y")-65)
      Locate 0,1 : Print "            "
      Locate 0,1 : Print X,Y

      Wait Vbl 

   Next I

   '// Because we operate on decimals the final coordinates are not always..
   '// ..the same as of the mouse click (DESTX, DESTY). In order to make..
   '// ..sure we get the Bob on its right position we send only once the..
   '// ..final coordinates (Rem those lines and click a destination and.. 
   '// ..do NOT move the mouse pointer to see what I mean)
   Amreg(Asc("X")-65)=DESTX : Rem // Pass the original mouse X value to the Register X   
   Amreg(Asc("Y")-65)=DESTY : Rem // Pass the original mouse X value to the Register Y   
   A$="Let X=RX; Let Y=RY"
   Amal 3,A$
   Amal On 3

End Proc

Last edited by Epo; 01 September 2018 at 20:34.
Epo is offline  
Old 30 August 2018, 22:48   #3
Predseda
Puttymoon inhabitant
 
Predseda's Avatar
 
Join Date: Mar 2007
Location: Tromaville
Age: 46
Posts: 7,538
Send a message via ICQ to Predseda
No, I can't get it. There is an example for Amreg in AMOS Help, but it uses that for maintenance the speed of the game. I just want to read mouse coords to a variable and use it as a target point for a bob to move to. A routine where bob follows the clicked point on the screen. Seems AmReg is somehow able to gather the coords and store them in RA-RZ (R0-R25) register (variable)?

Like
Code:
Amreg(RA)=XM
?

EDIT:
A partial success. I adjusted my procedure to look as this:

Code:
Procedure MOVEMENT
Amreg(RB)=Y Mouse-42-B
Amreg(RA)=X Mouse-128-A
Bob 3,A,B,3
A$="S: Move RA,RB,100; Pause;"
Amal 3, A$
Amal On 3
End Proc
Bob now goes to coords of the mouse click and stops there, but only horizontally. Vertically it keeps its position. When I list RA and RB, both have the same values: RA, which is horizontal difference between Bob starting point and the pixel clicked (which is correct for X-movement, but what should I do to get RB, that would move Bob vertically?)

Last edited by Predseda; 31 August 2018 at 09:42.
Predseda is offline  
Old 31 August 2018, 15:27   #4
Amiten
Banned
 
Join Date: May 2011
Location: Spain
Posts: 519
Hi predseda , insert the Mouse Coordinates in the main Loop then you get what you are looking for the Amreg's need to be looped(udpdate) inside ThE Amal or outside but update al the time if you want to get the right coordinates of the mouse

Last edited by Amiten; 31 August 2018 at 15:40.
Amiten is offline  
Old 31 August 2018, 16:37   #5
Amiten
Banned
 
Join Date: May 2011
Location: Spain
Posts: 519
but I dont understand really what you want to do ... but here the way you need to use the Amal to make a object position are in the X & Y of the mouse when we press key and maybe is not what you are looking for, if you explain me better your Idea may I can help you , regards

Get Sprite Palette
Cls 0
Global A,B
A=Rnd(200) : B=Rnd(100)
Bob 1,A,B,1
Procedure MOVEMENT
Amreg(0)=X Mouse-128
Amreg(1)=Y Mouse-42
A$="A:Move RA,RB,100;Pause;"
Bob 3,Amreg(0),Amreg(1),2
Amal 3,A$
Amal On 3
End Proc
Do
If Mouse Key=1 Then MOVEMENT
Loop

this example red square are bob 1 and white bob 3

https://drive.google.com/open?id=1NJ...dcTMh2IXpdc-CY


Example source code: https://drive.google.com/open?id=19f...JKqcDJTzxGkWsZ

Last edited by Amiten; 31 August 2018 at 16:43.
Amiten is offline  
Old 01 September 2018, 20:11   #6
Epo
Users Awaiting Email Confirmation
 
Join Date: Aug 2018
Location: Country
Posts: 38
Look at post #2. I provided a solution.
Epo is offline  
Old 02 September 2018, 22:34   #7
Predseda
Puttymoon inhabitant
 
Predseda's Avatar
 
Join Date: Mar 2007
Location: Tromaville
Age: 46
Posts: 7,538
Send a message via ICQ to Predseda
Thank you guys. I am just examining your examples. It still doesnt do exactly what I want, but I am sure I will learn something from you and finally get into it. I will let you know.

EDIT: GOT IT!
I altered my original procedure from what you both suggested and now it looks like this:

Code:
Procedure MOVEMENT
Amreg(0)=X Mouse-128-A
Amreg(1)=Y Mouse-42-B
Bob 3,A,B,3
A$="S: RA, RB, 100; Pause;"
Amal 3,A$
Amal On 3
End Proc
It now does exactly what I wanted. Thank you Epo for pointing me to the Amreg command, that I didnt know and thank you Johnnny for getting me an idea how to use it.


Last edited by Predseda; 02 September 2018 at 22:58.
Predseda is offline  
Old 04 September 2018, 22:34   #8
volvo_0ne
Registered User
 
Join Date: Mar 2015
Location: Sheffield UK
Posts: 360
Of course ..

If you are defining an animation string from basic at each turn, you could do ...

a$="Move "+str$(xmoves)+","+str$(ymoves)+","+str$(totalsteps)+"anything else"

where xmoves,ymoves & totalsteps are standard basic variables at runtime

Not ideal but it's easier to grasp (a bit like a virtual compiler)

Also, if you are using AMAL registers take a look at AMREG (channel,register) in the manual as these variables are local to the routine rather than the whole AMAL system.


In short, treat each AMAL channel as a self contained mini program UNLESS you need to share information between channels, only then use the global registers


One other thing....

In the examples above, what would happen if the mouse button was clicked again before the Move instruction had completed?

I assume it would re-calculate all the co-ordinates and try again, which would seem very slow (unless that is the idea)

Otherwise I'd suggest looking at the AU (AUtotest) function in AMAL

Last edited by volvo_0ne; 04 September 2018 at 23:30.
volvo_0ne is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
AMAL as primary code... volvo_0ne Coders. AMOS 14 13 April 2018 01:59
AMAL channel n to object n limit?? volvo_0ne Coders. AMOS 1 07 October 2017 21:18
Amal animation & HREV with joystick commands Brick Nash Coders. AMOS 8 02 June 2016 18:32
Animating explosion without amal aszu Coders. AMOS 13 17 March 2016 23:33
More AMAL headaches.... volvo_0ne Coders. AMOS 0 23 February 2016 00:17

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 11:54.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.07416 seconds with 13 queries