Author Topic: SwitchToState return values (need HasStateChanged or sth)  (Read 4633 times)

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
copied from the help:
SwitchToState
Return Value

True if the state could be switched, false if the new state's differing size would have caused the sprite the sprite to pass through a solid tile.

but i don't know how to deal with that.
i had the idea of making a query(?), which asks whether the state is been changed.
so i could make sth. like this: has state changed? if true, do sth other...

for a few days now, i try to script a behaviour for a sprite at a path.
when dx>0 then it has the state right, else left.
but since it is a huge, slow zeppelin, at every state change it needs to turn around slowly.
but i have searched so long, and didn't find a term which tells me if there was a state change, or dx/dy change. maybe an OldDX and OldDY would be usefull.
i get the feeling i started totally wrong with that "when dx>0 then it has the state right, else left." rule. many problems come from here.
looking at the sample sprites brought nothing, because they walk until they are blocked. but my sprite moves on a path.

other try:
now i wanted to compare if the x of the coordinateIndex with the x of the next. but there is no "CoordinateIndex.x"

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: SwitchToState return values (need HasStateChanged or sth)
« Reply #1 on: 2007-11-23, 10:26:55 AM »
Did you look at the documentation for PlanBase?
PlanBase has an indexed Item property, which can be used to access the x and y coordinates of each coordinate in the plan.  Item is actually a "special" name for the default property (this is a feature of the .NET Framework or the .NET compilers) , so it doesn't really have a property called "Item", but you can use "this" to refer to the current plan, and then use brackets [] to refer to a coordinate in the plan.  See the documentation page about the Item property for an example.

Your rules should know when a state change happens because they are responsible for changing the state.  If you want to remember that information for later, put it in a sprite parameter.  Instead of changing the state, maybe you have to change some sprite parameter called "turning" or something.  Then you can use the turning parameter to make other rules that affect how the sprite behaves when it's turning.

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: SwitchToState return values (need HasStateChanged or sth)
« Reply #2 on: 2007-12-01, 09:19:30 AM »
there is a thing i am not sure if i got it right.
say the player is moving rightwards. therefore his dx is always > 0.
if there is a rule which says: "if dx > 0, than switchToState right"

what happens now at runtime? doesn't the game switch the state at every frame the player is moving rightwards? (what a normal eye doesn't notice, but it happens)
or does the game switch the state only one time at the beginning of the movement?

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: SwitchToState return values (need HasStateChanged or sth)
« Reply #3 on: 2007-12-01, 11:29:05 AM »
It would switch on every frame.