persistenref problems?

Discussion of Inner Space

Moderators: Lavish Software Team, Moderators

Post Reply
mistahmikey
GamingTools Subscriber
Posts: 29
Joined: Wed Jun 30, 2010 7:48 am

persistenref problems?

Post by mistahmikey » Tue Mar 18, 2014 10:28 pm

The following script:

Code: Select all

objectdef Test
{
	variable persistentref M_MySet

	method SetMySet(persistentref MySet)
	{
		M_MySet:Set[MySet]

		echo ${M_MySet.Used}
	}

}

function main()
{
	variable set  MySet
	variable Test MyTest

	echo ${MySet.Used}

	MyTest:SetMySet[MySet]
}
prints out

Code: Select all

0
NULL
The following script:

Code: Select all

objectdef Test
{
	variable string M_Name

	method Initialize(string Name)
	{
		M_Name:Set[${Name}]
	}

	member ToText()
	{
		return ${M_Name}
	}
}

function main()
{
	variable collection:Test MyCollection

	MyCollection:Set["key1","value1"]
	MyCollection:Set["key2","value2"]

	variable persistentref MyTestRef

	MyTestRef:Set[MyCollection.Element["key2"]]

	echo ${MyTestRef}
	echo ${MyCollection.Element["key2"]}
}
prints out

Code: Select all

NULL
value2
Is this behavior correct? If so, why?

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

Post by Lax » Wed Mar 19, 2014 9:24 am

#1. persistentref does not have a "Set" method. Its method is called "SetReference". Correct behavior. https://www.lavishsoft.com/wiki/index.p ... ersistence

#2. persistentref does not have a "Set" method. Its method is called "SetReference". Correct behavior. https://www.lavishsoft.com/wiki/index.p ... ersistence

"Set" is NOT a universal method. (There are no universal methods)

mistahmikey
GamingTools Subscriber
Posts: 29
Joined: Wed Jun 30, 2010 7:48 am

Post by mistahmikey » Wed Mar 19, 2014 11:22 am

Doh! Sorry about that. Thanks for your patience :)

mistahmikey
GamingTools Subscriber
Posts: 29
Joined: Wed Jun 30, 2010 7:48 am

Post by mistahmikey » Wed Mar 19, 2014 7:36 pm

Well, still not out of the woods. For the second script, I changed the Set to SetReference, but I still get the same result. I am also encountering NULL when I use SetReference to get a reference to a collection member object in my main code.

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

Post by Lax » Thu Mar 20, 2014 10:28 am

Final problem is that you also need to satisfy the parser.

This is a malformed statement:

Code: Select all

   MyTestRef:SetReference[MyCollection.Element["key2"]]
The parser doesn't know that what you are putting in the brackets is an object, it's just text. So it's getting to the first ] and believes that is the end of the sequence -- as in .. MyTestRef:SetReference[MyCollection.Element["key2"].

You need to remove the behavior of that bracket. There's 2 ways to remove the behavior of special characters: quote it, or escape it.

Escaped special character:

Code: Select all

MyTestRef:SetReference[MyCollection.Element["key2"]\]
Quoted entire parameter (note that the inner quotes must be escaped for the same reason):

Code: Select all

MyTestRef:SetReference["MyCollection.Element[\"key2\"]"]
Working code with quote method:

Code: Select all

objectdef Test
{
   variable string M_Name

   method Initialize(string Name)
   {
      M_Name:Set[${Name}]
   }

   member ToText()
   {
      return ${M_Name}
   }
}

function main()
{
   variable collection:Test MyCollection

   MyCollection:Set["key1","value1"]
   MyCollection:Set["key2","value2"]

   variable persistentref MyTestRef

   MyTestRef:SetReference["MyCollection.Element[\"key2\"]"]

   echo ${MyTestRef}
   echo ${MyCollection.Element["key2"]}
} 

Post Reply