Posted: 26th Oct 2021 6:14
one of the fundamental principles of coding is instinctively knowing what to use where ... this will come with experience, and good advice form forum members


Boy am I finding out that to be so true.

I think I have restructured this code at least 4 times after learning new things.

But I think I understand arrays a lot better then i did and this will help me with future code and also what to put where and why.
Posted: 27th Oct 2021 1:42
Hello my good coding friends.

I have a small crazy situation.

I have snakes in my level, each snake is set in a array.

That works great.

But when they attack they attack with there sprite flip is the wrong way and right way.

How do I check what side of each snake is on from my player? then flip there sprites accordingly?

I was thinking maybe

if getspritex(player)>getspritex(snake) setspriteflip(snake,0,0)
if getspritex(player)<getspritex(snake) setspriteflip(snake,1,0)

untested

what is the best way?

EDIT:

I tried this and it works but at a point some of them flip back and forth like crazy.

+ Code Snippet
if Snakes[m].attack =1 and Snakes[m].idel =0
SetSpritePhysicsVelocity(Snakes[m].ID,0,0)	
PX# = GetSpriteXByOffset(Player)	:	PY# = GetSpriteYByOffset(Player)
SX# = GetSpriteXByOffset(Snakes[m].ID)	:	SY# = GetSpriteYByOffset(Snakes[m].ID)
if PX#&gt;SX# then setspriteflip(Snakes[m].ID,0,0)
if PX#&lt;SX# then setspriteflip(Snakes[m].ID,1,0)
endif
Posted: 27th Oct 2021 13:31
Try adding a little padding, a few pixels either side of the player (PX#-3>SX#) (PX#+3<SX#)
Posted: 27th Oct 2021 20:00
Try adding a little padding


I did, and it still does it and I figured out why.

It is in a continuous loop

if SnakeDis=<30 and SnakeDis=>15

I need to set it to flip on like this I believe.

if SnakeDis=30 without the <>

Thank you for the help either way.
Posted: 28th Oct 2021 2:06
I have a set up where the player is moving between swinging spikes

I need the spikes to keep swinging at the same pace back and forth.

this does not work at all

+ Code Snippet
inc Push_Swing[ Hang_Swing].timers
print(Push_Swing[ Hang_Swing].timers)

if Push_Swing[ Hang_Swing].timers&gt;99 and Push_Swing[ Hang_Swing].timers&lt;100

if Push_Swing[ Hang_Swing].Plus=0
SetSpritePhysicsVelocity(Push_Swing[Hang_Swing ].Id,100,-20)	
endif


if Push_Swing[ Hang_Swing].Plus=1
SetSpritePhysicsVelocity(Push_Swing[Hang_Swing ].Id,-100,-20)	
endif

endif


Edit:

I figured it out

+ Code Snippet
inc PushThisSwing

for Hang_Swing=55 to 59

Push_Swing[Hang_Swing].Push_Y=GetSpriteYByOffset(Hang_Swing)
Push_Swing[Hang_Swing].Push_X=GetSpriteXByOffset(Hang_Swing)


if PushThisSwing=74 and Push_Swing[Hang_Swing].Plus=0
SetSpritePhysicsImpulse ( Hang_Swing, GetSpriteXByOffset(Hang_Swing),GetSpriteYByOffset(Hang_Swing), GetSpriteXByOffset(Hang_Swing), 0 )
endif

if PushThisSwing=74 and Push_Swing[Hang_Swing].Plus=1
SetSpritePhysicsImpulse ( Hang_Swing, GetSpriteXByOffset(Hang_Swing),GetSpriteYByOffset(Hang_Swing), -GetSpriteXByOffset(Hang_Swing), 0 )
endif

next Hang_Swing

if PushThisSwing&gt;76 then PushThisSwing=0
Posted: 31st Oct 2021 4:42
So I have a array set up for the life time of each arrow shot.

it counts the arrow timer for each then zeros out after the arrow has been deleted.

What I'm worried about is my program storing all the timed 0 variable's in memory for no reason, if it doesn't exist what is the point?
will it slow down my program after awhile? Is there a way to rem memory after each delete sprite?

+ Code Snippet
	    if GetSpriteExists(ArrayOfArrows[x].ID)=1
            ArrayOfArrows[x].LifeTime= ArrayOfArrows[x].LifeTime+1 
            if ArrayOfArrows[x].LifeTime=&gt;100
           	DeleteSprite ( ArrayOfArrows[x].ID )
           	ArrayOfArrows[x].LifeTime=0
			endif     
			endif                                           
            print(ArrayOfArrows[x].LifeTime)
Posted: 31st Oct 2021 11:40
DOT REMOVE X

.remove(x)
Posted: 31st Oct 2021 18:35
ArrayOfArrows.remove(x)

this worked, thank you PartTimeCoder

But I had a array error so I had to ask if the array was over 0

if ArrayOfArrows.Length>0 then ArrayOfArrows.remove(x)
Posted: 31st Oct 2021 20:21
Remember that if you are looping throught the array and deleting elements as you go then you should loop from the end of the array through to zero or you will skip entries or get the error you mentioned
Posted: 31st Oct 2021 20:32
blink0k

Yes, and sometimes when you are shooting bullets' or arrows I noticed if you have more then one it will also give me a error so I am only shooting one bullet at a time.

+ Code Snippet
	if GetSpriteExists(shot[x].ID)=1
        shot[x].LifeTime= shot[x].LifeTime+1
        if shot[x].LifeTime=&gt;50
		SetSpritePhysicsOff(shot[x].ID)
        DeleteSprite ( shot[x].ID )  
       if shot.Length=shot.Length then shot.remove(shot.Length)                                     
        endif  
Posted: 31st Oct 2021 22:08
Ok here is a little update on level 3

took me awhile to figure out some array stuff but added a lot.
Posted: 2nd Nov 2021 17:05
There's nothing there that would indicate to me that the barrels could be broken by jumping on them. Do you have something planned to show that? Or is that intended to be a hidden thing?
Posted: 2nd Nov 2021 19:35
Do you have something planned to show that? Or is that intended to be a hidden thing?


Yes, you can break boxes barrel's and chests, this will be a known event in the game. < almost have the timing perfect but sometimes you can easily break two at a time, I'm trying to fix this.

The bird is dropping mad amount of rocks on you as you try to dodge arrows so breaking the boxes are a good way to avoid things for a time period.

The next level is a water level where you have to jump from platform to platform and not get pulled into the water by something.
Posted: 3rd Nov 2021 0:45
Help

This is driving me crazy, I had tried everything

I am creating water for my levels, with a water shader that looks cool and works good.

But when I add clones to my level then I line them right next to each other, there is a border line, if to close, but if one point away there is a line between them.

I know it is mostly because of the transparency but still, they can not be that close in to each other.

I've tried

SetSpriteUVBorder(clone_1,0)
setimagemagfilter(clone_1,1)
setimageminfilter(clone_1,1)

Edit:

Never mind, I figured out that setting the sprite offset before hand was making it do this.
Posted: 6th Nov 2021 1:09
What am I doing wrong, its not returning any find for my array

+ Code Snippet
PX# = GetSpriteXByOffset(Player)	:	PY# = GetSpriteYByOffset(Player)	

			    SetSpriteVisible(line ,1)  
			    drawSpriteLine(line, PX#,PY#,PX#,PY#+15, 2) 

If GetSpriteFirstContact(Player)
        Repeat
			    PlayerFeet = PhysicsRayCast( PX#,PY#,PX#,PY#+15)
                EnemyHead = GetRayCastSpriteID()
                EnemyHit = GetSpriteContactSpriteID2()
                
                print(EnemyHit)
                If EnemyHit &gt; 0 and All_Enemy.Find(EnemyHit) &gt; -1
                Enemy = All_Enemy.Find(EnemyHit)
    EndIf
           
    Until GetSpriteNextContact() = 0
    EndIf


Edit:

Never mind lol

I just used PlayerFeet = PhysicsRayCastGroup( -100,PX#,PY#,PX#,PY#+15 )

PhysicsRayCastGroup