LavishScript Object Wrappers

Discussion of Inner Space

Moderators: Lavish Software Team, Moderators

Post Reply
bountycode
Non-Subscriber
Posts: 22
Joined: Mon Jul 12, 2004 8:27 am

LavishScript Object Wrappers

Post by bountycode » Thu Dec 14, 2006 5:20 pm

I am having difficulties wrapping objects in .Net
This direct command button sub below works.
It returns the value of Me.ToActor.Health by grabbing the object Me then the member ToActor then the Member Health

Code: Select all

    Private Sub cmdMeToActorHealthFunction_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdMeToActorHealthFunction.Click
        LavishVMAPI.Frame.Lock()
        Dim vObj As LavishScriptObject = LavishScript.Objects.GetObject("Me")
        If IsNothing(vObj) Then
            InnerSpace.Echo("object Me not found")
        Else
            Dim vToActorObj As LavishScriptObject = vObj.GetMember("ToActor") '${Me.ToActor}
            If Not IsNothing(vToActorObj) Then
                Dim vHealthObj As LavishScriptObject = vToActorObj.GetMember("Health") '${Me.ToActor.Health}
                If Not IsNothing(vHealthObj) Then
                    Dim vHealth As Integer = vHealthObj.GetValue(Of Integer)()
                    InnerSpace.Echo("Me.ToActor.Health=" & vHealth)
                End If
            End If
        End If
        LavishVMAPI.Frame.Unlock()
    End Sub
trying to wrap this in objects using classes is not working for me.

I have my me class

Code: Select all

Public Class ISXEQ2_Me
    Inherits ISXEQ2_character

    Public Sub New(ByVal Obj As LavishScriptObject)
        MyBase.New(Obj)
    End Sub
End Class
Then the character class

Code: Select all

Public Class ISXEQ2_character
    Inherits LavishScriptObject

    Public Sub New(ByVal Obj As LavishScriptObject)
        MyBase.New(Obj)
    End Sub

    Public ReadOnly Property Name() As String
        Get
            LavishVMAPI.Frame.Lock()
            Dim vRet As String = GetMember(Of String)("Name")
            LavishVMAPI.Frame.Unlock()
            Return vRet
        End Get
    End Property

    Public Function ToActor() As ISXEQ2_Actor
        LavishVMAPI.Frame.Lock()
        Dim vRet As ISXEQ2_Actor
        vRet = New ISXEQ2_Actor(GetMember(Of LavishScriptObject)("ToActor"))
        ' I also tried the line below
        'vRet = New ISXEQ2_Actor(LavishScript.Objects.GetObject("ToActor"))
        LavishVMAPI.Frame.Unlock()
        Return vRet
    End Function
End Class
and finally the actor class

Code: Select all

Public Class ISXEQ2_Actor
    Inherits LavishScriptObject

    Public Sub New(ByVal Obj As LavishScriptObject)
        MyBase.New(Obj)
    End Sub

    Public ReadOnly Property Health() As Integer
        Get
            LavishVMAPI.Frame.Lock()
            Dim vRet As Integer = GetMember(Of Integer)("Health")
            LavishVMAPI.Frame.Unlock()
            Return vRet
        End Get
    End Property
End Class
the setup function looks like this

Code: Select all

    Public Function GetISXEQ2_Me() As ISXEQ2_Me
        Return New ISXEQ2_Me(LavishScript.Objects.GetPermanentObject("Me"))
    End Function
I know the classes are mostly correct because the line below works

Code: Select all

mee = GetISXEQ2_Me()
InnerSpace.Echo("${Me.Name}=" & Mee.Name)
but this line does not

Code: Select all

InnerSpace.Echo("${Me.ToActor.Health}=" & Mee.ToActor.Health)
I have been trying all kinds of different combinations but I just can't seem to figure out how to structure a class so that a method returns another innerspace object. I can't get the character object to return a member from the actor object. What am I missing?

Lax
Owner
Posts: 6634
Joined: Fri Jun 18, 2004 6:08 pm

Post by Lax » Thu Dec 14, 2006 6:47 pm

Is "Me" a permanent object in ISXEQ2? I would assume you shouldn't be using a permanent object there.
I know the classes are mostly correct because the line below works
.
.
but this line does not
The code you're referring to MUST be used in frame lock, because you are dealing with temporary objects. This is exactly why your cmdMeToActorHealthFunction_Click function works -- it is used in frame lock. However, the code you're talking about NOT working, you gave no context for, and the descirption of the problem fully indicates to me that it is used outside of frame lock.

See http://www.lavishsoft.com/wiki/index.ph ... me_Locking

Post Reply