Author Topic: Special func's activating series of special func's problem.  (Read 7051 times)

Dr Obvious

  • Regular
  • **
  • Posts: 53
    • View Profile
    • http://www.drobvious.net
I have a series of functions that activate other special functions and they check to make sure the player has certain variables in their inventories.  The order goes like this:

L- L Group
  -Uses Inventory Item: Facing Left
  -Global
  -Initial press of button 2
  -Activates Series of special functions
    -L- L Check

L- L Check
  -Uses Inventory Item: Level 3
  -Activates Series of Special Functions
    -...4 functions that don't  really matter right now


The problem is, I can press button 2 when I have the Level 3 inventory item and everything works fine, but  the problem is that when I don't have the Level 3 inventory item, the series of special functions activated by L- L Check is still activated.  How do I make a series of special functions that checks for two inventory items or what am I doing wrong here?


Note:  My first and third level use the same map, just you come to it at different times and have different abilities so that's why I have the Level 3 inventory items and why I don't inclue these functions in the previous levels.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Activation Parameters
« Reply #1 on: 2005-09-08, 05:52:38 AM »
Activation parameters only apply to activating the function by touching it.  When a function is activated by a collision or a tile interaction or another function, the activation parameters are ignored.  There is no good way to require multiple different items without scripting.  The best option without scripting would involve teleporting the player from location to location to activate other functions by touching them, but putting the player back where it belongs if something doesn't meet the requirements could be quite a pain.  Perhaps the "switch map" function in combination with the "return to old map" feature would work for that.

Dr Obvious

  • Regular
  • **
  • Posts: 53
    • View Profile
    • http://www.drobvious.net
Special func's activating series of special func's problem.
« Reply #2 on: 2005-09-08, 08:14:00 AM »
Hmm, alright, but now another question, I'm really bad at GameDev scripting so is there a way to use the special functions I already have or do I need to remake them all in a script?  If I couldn't use my special functions, would the script go something like this? (I can't remember the function names off the top of my head)

Sub OnControlChange(old, new)
  Button2(go to shooting function)
End Sub

Sub Shooting
  If (Facing Left) && (Level 3) && (Laser Units <> 0) Then 'Facing Left, Laser Units and Level 3 are inventory items I have defined
  SwitchPlayerSprite(Bob Laser Left) 'switches relative to player sprite
  CreateSprite(Beam)
  Laser Units = 10
 End If
End Sub

Sub LaserTimer
  'Timer starts at 10 and goes to 0 (by a special function in the game, when at 0, the player sprite gets switched from the shooting sprite to the original player sprite
  If (Laser Timer == 0) Then
    SwitchPlayerSprite(Bob)
  End If
End Sub

Dr Obvious

  • Regular
  • **
  • Posts: 53
    • View Profile
    • http://www.drobvious.net
Special func's activating series of special func's problem.
« Reply #3 on: 2005-09-08, 09:43:27 AM »
Actually, if you can access your special functions through scripting, could I just use a script to make a special function global at one point in my game?

Like when I set my variable "Level 3" in the game can I make it so my script sees that (Sub onPlayerMove maybe?) and then when it sees that I access my two special functions I want to make global by setting the bits in flag1 or flag2?  Also, I'm still not real sure on how to access my special functions.  Sorry about so many questions, just trying to figure things out here. :P

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Activating a function from script
« Reply #4 on: 2005-09-08, 05:16:30 PM »
You can activate your function from script directly with something like this.  Make sure to check the box for "raise an event" on the "L-L Group" function, or whatever function should trigger this script to execute.
Code: [Select]
Sub Player_OnSpecialFunction(Func)
   ' If a function named "L-L Group" activates, check to see
   ' That the player has some of inventory item #1, and if so
   ' then activate a function called "L-L Check" on the current map
   If Func.Name = "L-L Group" Then
      With ProjectObj.GamePlayer
         If .InvQuantityOwned(0) > 0 Then
            .ActivateFunction .rMap.Specials("L-L Check")
         End If
      End With
   End If
End Sub


That sample is based on your original function sequence.  To use your more recent example, I think it would go something like this:
Code: [Select]

Sub Player_OnControllerMove(OldActions, NewActions)
   If (OldActions And ACTION_BUTTON2) = 0 And _
      (NewActions And ACTION_BUTTON2) <> 0 Then
      OnButton2Pressed
   End If
End Sub

Sub OnButton2Pressed
   With ProjectObj.GamePlayer
      ' 0=Left for a 2-state sprite
      ' Assumes the the Level 3 map is called "Level3"
      ' And that inventory item #1 is Laser Units
      If (PlayerSprite.CurState Mod 2) = 0 And _
         .rMap.Name = "Level3" > 0 And _
         .InvQuantityOwned(0) > 0 Then
         ' Activate a function called "ShootLeft" on the current map
         ' Let it do the rest of the work.
         .ActivateFunction .rMap.Specials("ShootLeft")
      End If
   End With
End Sub


(edit) Changed the call to "Button2Pressed" to "OnButton2Pressed" because I changed the function name, but forgot to change the call.

Dr Obvious

  • Regular
  • **
  • Posts: 53
    • View Profile
    • http://www.drobvious.net
Special func's activating series of special func's problem.
« Reply #5 on: 2005-09-08, 07:26:07 PM »
Awesome, thanks for the help! ^^

-edit-
And on a random note, great job on your random final boss thing you did.  That actually helps with a few other things I've been having troubles with!

Dr Obvious

  • Regular
  • **
  • Posts: 53
    • View Profile
    • http://www.drobvious.net
Special func's activating series of special func's problem.
« Reply #6 on: 2005-09-09, 11:46:16 AM »
Alright, so I'm trying the first script, and this is what I have:

Code: [Select]

Sub Player_OnSpecialFunction(Func)
'If a function named L-L Group activates, check to see if
'that player has some of inventory item #1, and if so,
'then activate a function called "L- L Check" on the current map
'Inventory item "Level 3:' = index 22
'Inventory item "Facing Left" = index 15
'Inventory item "Facing Right" = index 14
if Func.Name = "L- L Group" Then
With ProjectObj.GamePlayer
If .InvQuantityOwned(21) > 0 Then
.ActivateFunction .rmap.Specials("L-L Check")
End If
End With
End If
End Sub

HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.ConnectEventsNow()
ProjectObj.GamePlayer.Play 16


That's my entire script at the moment, do I need more?  Right now, no matter what inventory item I set it to check if greater than 0, the function seems to go off.  What's supposed to happen is the function "L-L Group" is only supposed to go off if the inventory "Facing Left" is set to 1.  After it checks  that then the script should set if the inventory item "Level 3:" is set to 1 and then activate "L-L Check" which then activates a series of special functions.  Right now, no matter what I put as the inventory item number, the who script goes off.  Here's what I have set on those functions:


L- L Group
Action Parameters
  -Uses inventory item "Facing Left" (1)
  -Global
  -Pressing button 2
  -Initial press only
  -Raise an event when this function is activated
Effect
  -Activate a series of special functions
    -"L- LCheck"

L- L Check
Action Parameters
  -Raise an event when this function is activated
Effect
  -Activate a series of special functions
    -"L- Dec Recharge"
    -"L- L Beam"
    -"L- Laser"
    -"L- Add Units"

-edit-
Nevermind, I'm a big idiot, I checked the activate the special functio box but I didn't put it in the effects tab!

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Special func's activating series of special func's problem.
« Reply #7 on: 2005-09-09, 05:00:39 PM »
I don't understand your edit.  I think you should have to change your "L-L Group" function so that it doesn't do anything (it should be of type "Raise an event") otherwise it will always activate L-L Check.  Then the script will activate L-L Check again when it sees that it needs to be activated.