Author Topic: Setting sprite parameters in Plan rules  (Read 4932 times)

ststrou

  • Visitor
  • *
  • Posts: 8
    • View Profile
Setting sprite parameters in Plan rules
« on: 2007-11-17, 04:38:59 PM »
Let's say I'm defining a plan for a layer.  Under certain conditions the plan will add a new enemy sprite using AddSpriteAtPlan.  I would like to then set certain Parameters on the sprite.  And I would like to do so in the rules for the plan (not the rules for the sprite).  So after calling AddSpriteAtPlan, I think I want to call SelectTargetSprite.  But what value do I give for the "Index"?

 

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Setting sprite parameters in Plan rules
« Reply #1 on: 2007-11-17, 06:55:17 PM »
Is there a reason you don't want to initialize the sprite itself to initialize the values?  It would simplify things. Otherwise:

SelectTargetSprite works only if you have a Sprite Collection you're working with and a simple way to get a particular index into that array for a specific reason (such as TestCollisionMask()).  In this case, the quickest way to reference the sprite is to use lastCreatedSprite.  For example, if you wanted to set a parameter called "Speed" to 5 on a "Platform" sprite that you just created, you could create a rule like this:

Code: [Select]
Rule Type: Do
Action: =
Value: 5
Output to: ((Sprites.Platform)lastCreatedSprite).Speed

the lastCreatedSprite value is set whenever AddSpriteAtPlan is called, so if you put this rule right after that one, it will assign the value you choose to the parameter you defined.  Just replace the "Platform", "Speed" and "5" with what you really want to use.

Another option would be instead of using SelectTargetSprite, just set the selected sprite manually with a rule like this:
Code: [Select]
Rule Type: Do
Action: =
Value: lastCreatedSprite
Output to: selectedTarget
You'd have to modify the source code for this to work, however.  In GeneralRules.cs, you'd have to change
Code: [Select]
private static SpriteBase selectedTarget; to
Code: [Select]
public static SpriteBase selectedTarget;.  If you did make this change, this is probably the better method for error handling.  Again, I should point out, setting the values within the sprite rules would be simpler.
« Last Edit: 2007-11-17, 07:03:49 PM by durnurd »
Edward Dassmesser

ststrou

  • Visitor
  • *
  • Posts: 8
    • View Profile
Re: Setting sprite parameters in Plan rules
« Reply #2 on: 2007-11-17, 07:02:15 PM »
Ok, I see.  How did you know about the "lastCreatedSprite" variable?  It doesn't show up in dropdown lists or anything and I didn't see it in the documentation.  I'm wondering if there other such variables I might want to use.  Is there any documentation for them somewhere or do you just have to "know" about them (maybe by looking at the generated code?).  Another example of such a variable is "state", which is a member of Sprite.

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Setting sprite parameters in Plan rules
« Reply #3 on: 2007-11-17, 07:05:55 PM »
Well, I know about lastCreatedSprite because I've worked a lot with project source code and generated sprites.  It's also in the documentation, but it should also probably show up in the dropdown lists. (Hint, hint, BlueMonk).

The documentation does exist for all of the classes under the help menu (Help->Contents->SGDK2 Help->Coding Reference).
Edward Dassmesser

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: Setting sprite parameters in Plan rules
« Reply #4 on: 2007-11-18, 05:01:45 AM »
It's also in the documentation, but it should also probably show up in the dropdown lists. (Hint, hint, BlueMonk).

yes, that should make it better to use. i read about it in the help, but (as i am new to scripting) i wouldn't know how to use it in a construct like:
((Sprites.Platform)lastCreatedSprite).Speed