Checking hero alignment (Is this script adequate)?

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Checking hero alignment (Is this script adequate)?

Post by sheamkennedy »

I want a script which checks if my hero is aligned. Here's the script I wrote, however I wasn't sure if I also have to account for hero offset value...

Code: Select all

script, check alignment, begin 
  if((hero x(me) == hero pixel x(me)/20) && (hero y(me) == hero pixel y(me)/20)) then(
    # The hero is currently aligned 
    heroIsAligned := true
  ) else (
    heroIsAligned := false
  )
end
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

That looks fine to me.

You don't have to care about foot offset or hero z. All that matters is the hero x and the hero y.
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

Great thanks!
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
User avatar
Spoonweaver
Liquid Metal King Slime
Posts: 6466
Joined: Mon Dec 08, 2008 7:07 am
Contact:

Post by Spoonweaver »

I don’t think this actually will work.
Won’t Heropixelx(me)/20 just round to the closest whole number?
Thus making this script always true?

I suggest also testing for (heropixelx(me)+20)/20
You should get all four points of the walkabout square too, while you’re at it.
Last edited by Spoonweaver on Tue Jan 16, 2018 6:56 pm, edited 2 times in total.
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

Spoonweaver wrote:I don’t think this actually will work.
Won’t Heropixelx(me)/20 just round to the closest whole number?
Thus making this script always true?

I suggest also testing for (heropixelx(me)+20)/20
You should get all four points of the walkabout square too, while you’re at it.
Yeah you're right, I just noticed this when I went to test it out. I think I got it working right by multiplying hero x*20 so that it will check if it's equal to hero pixel x at any given time. The check seems to work fine now.

Im curious what you mean about checking all four points of the walkabout square. I assume you're talking about checking whether the top-right, bottom-right, top-left, and bottom-left pixel line up with the grid properly. I just don't understand why this would be necessary to check. Could you explain further? As far as I understand checking if the one single point lines up (with both x and y) should tell me if my hero is currently aligned with the grid... or am I missing something important?
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

I think you could try

Code: Select all

if(hero pixel x(me),mod,20 == 0 && hero pixel y(me),mod,20 == 0) then( 
EDIT:
Just tested it, it works. Try this out for a test.

Code: Select all

plotscript, loop, begin
	suspend player
	while (true) do (
		if (keyval (key:up) == 3) then (
			put hero (me, hero pixel x(me), hero pixel y(me) --1)
		) elseif (keyval (key:right) == 3) then (
			put hero (me, hero pixel x(me)+1, hero pixel y(me))
		) elseif (keyval (key:down) == 3) then (
			put hero (me, hero pixel x(me), hero pixel y(me)+1)
		) elseif (keyval (key:left) == 3) then (
			put hero (me, hero pixel x(me)--1, hero pixel y(me))
		)
		if(hero pixel x(me),mod,20 == 0 && hero pixel y(me),mod,20 == 0) then (
			show value (1)
		) else (show value (0))
	wait
	)
end
Image
Last edited by Foxley on Wed Jan 17, 2018 2:08 am, edited 2 times in total.
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

Ah, good call Foxley. That’s probably the more condensed way of checking alignment. I’ll switch to that just because it’s easier to read.

I’m not doing pixel movement I just required a check to see if my hero is on the grid before carrying out an action for aesthetic purposes.
Last edited by sheamkennedy on Wed Jan 17, 2018 5:13 am, edited 1 time in total.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

"hero is moving(me) == false" accomplishes the same thing, except during cutscenes: if you hold down the, say, right arrow key, then "hero is moving" returns false at the end of every step. But if you run "walk hero(me, right, 4)" then "hero is moving" won't return false until the whole movement is finished.
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

TMC wrote:"hero is moving(me) == false" accomplishes the same thing, except during cutscenes: if you hold down the, say, right arrow key, then "hero is moving" returns false at the end of every step. But if you run "walk hero(me, right, 4)" then "hero is moving" won't return false until the whole movement is finished.
Good to know. I think I'll change to your method since it simplifies things further yet. I don't think the cutscene thing will raise any issues but I'll try to keep that in mind.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
User avatar
Spoonweaver
Liquid Metal King Slime
Posts: 6466
Joined: Mon Dec 08, 2008 7:07 am
Contact:

Post by Spoonweaver »

ah multiplying the grid by 20. good plan.

See, if you divide, you will always return the square the the top left corner is in. so the only way to detect alignment with dividing would be to check if each corner is aligned.

Your way. Much easier. Good job.
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Oops, "hero is walking", not "hero is moving".
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

TMC wrote:Oops, "hero is walking", not "hero is moving".
No worries I figured out what you meant.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Post Reply