Defining data structures in script?
by DavidRM · in Torque Game Engine · 04/24/2002 (10:53 am) · 10 replies
I'm wanting to create a simple data structure for use in a script.
I've perused the documentation and resources and tutorials...I've experimented with ScriptObject and DataBlocks...no dice.
All I want to do is create a simple data structure with a client ID and a message string. And I want to maintain an array of these in a separate (equally simple) data structure with a few access functions. Nothing too complex.
But I can't figure out how to make it happen in script. The script compiler is always complaining.
What am I missing? After all, this *has* to be possible...there is *no* way I'm limited to using only pre-defined data structures...
Thanks in advance!
-David
Samu Games
I've perused the documentation and resources and tutorials...I've experimented with ScriptObject and DataBlocks...no dice.
All I want to do is create a simple data structure with a client ID and a message string. And I want to maintain an array of these in a separate (equally simple) data structure with a few access functions. Nothing too complex.
But I can't figure out how to make it happen in script. The script compiler is always complaining.
What am I missing? After all, this *has* to be possible...there is *no* way I'm limited to using only pre-defined data structures...
Thanks in advance!
-David
Samu Games
#2
This is the current failure:
The error I get is on the attempt to create an instance of PrivateMessageVector.
That's actually where I've received the error for each attempt, even when I was using ScriptObject-based structures. In that case, the error was "attempting to instantiate a non-conobject" or something like that.
Thanks.
-David
04/24/2002 (11:32 am)
I've been through several iterations using ScriptObject and DataBlock.This is the current failure:
datablock GameBaseData(PrivateMessageItem)
{
Sender = 0;
Message = "";
};
datablock GameBaseData(PrivateMessageVector)
{
PMCount=0;
PMVector = 0;
};
function PrivateMessageVector::AddPM(%this,%sender,%message)
{
%this.PMVector[%this.PMCount]=new PrivateMessageItem();
%this.PMVector[%this.PMCount].Sender=%sender;
%this.PMVector[%this.PMCount].Message=%message;
%this.PMCount++;
}
readyRoomPrivateMessageVector=new PrivateMessageVector();The error I get is on the attempt to create an instance of PrivateMessageVector.
That's actually where I've received the error for each attempt, even when I was using ScriptObject-based structures. In that case, the error was "attempting to instantiate a non-conobject" or something like that.
Thanks.
-David
#3
$readyRoomPrivateMessageVector= new GameBaseData() {
datablock=PrivateMessageVector;
};
-J
04/24/2002 (12:02 pm)
This only my second day with Torque scripting... but I believe you have to do the following:$readyRoomPrivateMessageVector= new GameBaseData() {
datablock=PrivateMessageVector;
};
-J
#4
datablock GameBaseData(PrivateMessageItem)
{
Sender = 0;
Message = "";
};
datablock GameBaseData(PrivateMessageVector)
{
PMCount=0;
PMVector = 0;
};
function PrivateMessageVector::AddPM(%this,%sender,%message)
{
%this.PMVector[%this.PMCount]=new GameBaseData(){
datablock=PrivateMessageItem;
};
%this.PMVector[%this.PMCount].Sender=%sender;
%this.PMVector[%this.PMCount].Message=%message;
%this.PMCount++;
}
$readyRoomPrivateMessageVector=new GameBaseData()
{
datablock=PrivateMessageVector;
};
PrivateMessageVector::AddPM($readyRoomPrivateMessageVector,$readyRoomPrivateMessageVector,"hey");
04/24/2002 (12:16 pm)
The below compiles and appears to run for me, I don't know that the script language has a concept of creating new classes... notice the term datablock... I believe you can add functions to native cpp classes exposed to the script engine... but I don't think you can add a class in script itself.. I could be wrong...datablock GameBaseData(PrivateMessageItem)
{
Sender = 0;
Message = "";
};
datablock GameBaseData(PrivateMessageVector)
{
PMCount=0;
PMVector = 0;
};
function PrivateMessageVector::AddPM(%this,%sender,%message)
{
%this.PMVector[%this.PMCount]=new GameBaseData(){
datablock=PrivateMessageItem;
};
%this.PMVector[%this.PMCount].Sender=%sender;
%this.PMVector[%this.PMCount].Message=%message;
%this.PMCount++;
}
$readyRoomPrivateMessageVector=new GameBaseData()
{
datablock=PrivateMessageVector;
};
PrivateMessageVector::AddPM($readyRoomPrivateMessageVector,$readyRoomPrivateMessageVector,"hey");
#5
Thanks alot!
-David
Samu Games
04/24/2002 (12:25 pm)
That *is* compiling now, and even looks like it should do what it's supposed to. I'll be testing the whole thing later today. I'll report back how it goes...Thanks alot!
-David
Samu Games
#6
Also in digging thru some sample sources I noticed a className field which should work like inheritance...
I think I may pick thru Tribes2 scripts for some ideas... so far I like the scripting...
The process of discovery... currently I am trying figure out how I could call that PMAdd function without the namespace qualifier... I would think there would be some kind of syntax fixup which would allow you to use the obj.function() notation... I am probably just missing something...
-J
04/24/2002 (1:50 pm)
I am almost certain there would be another (better?) way of doing this... this resource could help: www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2212Also in digging thru some sample sources I noticed a className field which should work like inheritance...
I think I may pick thru Tribes2 scripts for some ideas... so far I like the scripting...
The process of discovery... currently I am trying figure out how I could call that PMAdd function without the namespace qualifier... I would think there would be some kind of syntax fixup which would allow you to use the obj.function() notation... I am probably just missing something...
-J
#7
The name of the object becomes the namespace. Sorta.
Thanks again!
-David
04/24/2002 (1:58 pm)
The datablockname::functionName does allow you to use the dot-notation: %obj.functionNameThe name of the object becomes the namespace. Sorta.
Thanks again!
-David
#8
function GameBaseData::AddPM(%this,%sender,%message)
or
function GameBaseData::PrivateMessageVector::AddPM(%this,%sender,%message)
If this is the way to do it, I would guess that the second is preferable to avoid namespace pollution?
Declaring with:
function PrivateMessageVector::AddPM(%this,%sender,%message)
causes the function not to be found with the %obj.function() notation.. I have to use the fully qualified PrivateMessageVector::AddPM(this,that,msg)
-J
04/24/2002 (2:15 pm)
I can declare either with:function GameBaseData::AddPM(%this,%sender,%message)
or
function GameBaseData::PrivateMessageVector::AddPM(%this,%sender,%message)
If this is the way to do it, I would guess that the second is preferable to avoid namespace pollution?
Declaring with:
function PrivateMessageVector::AddPM(%this,%sender,%message)
causes the function not to be found with the %obj.function() notation.. I have to use the fully qualified PrivateMessageVector::AddPM(this,that,msg)
-J
#9
$readyRoomPrivateMessageVector=new GameBaseData(PrivateMessageVector);
And voila... I like it!
-J
04/24/2002 (2:25 pm)
Duh:$readyRoomPrivateMessageVector=new GameBaseData(PrivateMessageVector);
And voila... I like it!
-J
#10
$classInstance = new ScriptObject() {
class = foo;
}
function foo::testIt(%this, %a) {
echo ("I am testing, " @ %a);
}
$classInstance.testIt("you!");
Outputs:
I am testing, you!
04/24/2002 (6:47 pm)
I've had good luck doing classes in this wise:$classInstance = new ScriptObject() {
class = foo;
}
function foo::testIt(%this, %a) {
echo ("I am testing, " @ %a);
}
$classInstance.testIt("you!");
Outputs:
I am testing, you!
Torque Owner Prairie Games
Prairie Games, Inc.
Could you post a snippet of what you have been trying?
-Josh