4.5 Get Random Action Step

Craigery

Active member
I would like to have the EndAction/EndAnimation User 0 slot change the object to a Random Action Step. In TimerEndScripts.asm, starting at line 153, I have changed the userEnd0_action to be this:


Code:
userEnd0_action:
		LDA Object_frame,x
		ora #%00111000
		STA Object_frame,x
		
		TXA 
		STA tempA
		
		JSR doGetRandomNumber
		STA tempB

		
		DoObjectAction tempA, tempB
		
	RTS


It doesn't appear to work though; am I approaching this wrong or misunderstanding doGetRandomNumber? Thanks in advance.
 

RadJunk

Administrator
Staff member
You have the perfect idea. The PROBLEM you are having is that right now doGetRandomNumber gives you a number between 0 and 255, and there are only 8 actions. So you need to flag off the high bits.

Code:
JSR doGetRandomNumber ;; gets random value between 0 and 255
AND #%00000111 ;; flags off the top 5 bits...now you have what remains between 0 and 7.
                     ;00000xxx will be a value between 0 and 7, because...
                             ;; 000 = 0
                             ;; 001 = 1
                             ;; 010 = 2
                             ;; 011 = 3
                             ;; 100 = 4
                             ;; 101 = 5
                             ;; 110 = 6
                             ;; 111 = 7

STA tempB ;; now tempB is between 0 and 7.  That should give you what you want :-)
 

dale_coop

Moderator
Staff member
TheNew8bitHeroes said:
You have the perfect idea. The PROBLEM you are having is that right now doGetRandomNumber gives you a number between 0 and 255, and there are only 8 actions. So you need to flag off the high bits.

Code:
JSR doGetRandomNumber ;; gets random value between 0 and 255
AND #%00000111 ;; flags off the top 5 bits...now you have what remains between 0 and 7.
                     ;00000xxx will be a value between 0 and 7, because...
                             ;; 000 = 0
                             ;; 001 = 1
                             ;; 010 = 2
                             ;; 011 = 3
                             ;; 100 = 4
                             ;; 101 = 5
                             ;; 110 = 6
                             ;; 111 = 7

STA tempB ;; now tempB is between 0 and 7.  That should give you what you want :-)


Oh, nice to see you here, Joe <3
(too many members now, on the forum, really difficult to reply to everyone... but glad to see more and more people are confident with code, sharing and helping each others.
 
Top Bottom