Scrolling Game Development Kit Forum

SGDK Version 1 => Script => Topic started by: tebakutis on 2006-11-16, 05:19:35 PM

Title: Running a Special Function from Code
Post by: tebakutis on 2006-11-16, 05:19:35 PM
I'm trying to figure out how to run a SpecialFunction created in the 'Special Functions' section of a map using code. Basically, I'd like to trigger the SpecialFunction from the code that runs with the game--I'm doing this to allow the same button to trigger two different special functions, with which SpecialFunction is implemented based on the character's inventory. Here's what I have so far.

Code: [Select]
Option Explicit

Sub Player_OnControllerMove(OldActions, NewActions)

    'The code below transforms the robot to car form
    'and the car to robot form using one button.

    'When the user presses button 1, covert to robot or
    'car form based on if the robot counter is in the
    'player's inventory.

    If ((OldActions And eActionBits.ACTION_BUTTON1) = 0) And _
       ((NewActions And eActionBits.ACTION_BUTTON1) <> 0) Then

       If ProjectObj.GamePlayer.InvQuantityOwned(2) = 1 Then
           'convert player to car
------> I need a line of code here that will trigger the special function that exists in my map.
           'subtract robot counter
           ProjectObj.GamePlayer.InvQuantityOwned(2) = 0
       Else
           'covert player to robot
------> I need a line of code here that will trigger the special function that exists in my map.
           'add robot counter
           ProjectObj.GamePlayer.InvQuantityOwned(2) = 1
       End If

    End If

End Sub


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

Here's additional information that relates to referencing the special functions.

- The map is called 'Roadtest'
- The layer on which the PlayerSprite resides is called 'bg' and is the only layer in the project.
- The SpecialFunctions in question are called 'TransformRobot' and 'TransformCar', and are the first two special functions on the layer.
- There is an item in the Player's inventory called 'RobotCounter' at index 3 which is set to 1 or 0 based on the form the player is in... this determines whether the player transforms from robot to car or car to robot.

So, I need a line of code that will trigger the existing TransformRobot and TransformCar Special Functions. I haven't been able to nail down the exact syntax to reference these, so any help is appreciated.
Title: Re: Running a Special Function from Code
Post by: bluemonkmn on 2006-11-16, 06:04:34 PM
It should look something like this:
ProjectObj.GamePlayer.ActivateFunction ProjectObj.GamePlayer.rMap.Specials("TransformRobot")

Examples are in the help file if you search for "ActivateFunction".