Angelscript - Initialization of List of Classes
- Ocelot
- Posts: 77
- Joined: Thu Oct 06, 2011 10:43 am
Angelscript - Initialization of List of Classes
PowerVision 2.9.10481
Working on some menu's in Angelscript.
Trying to create a class that in some ways mimics the functionality of the MPC-20 and MPC-10 menu system, right now I am just working on data types and filling the initial list of classes with data, with functions within the class to follow.
I believe I am having a syntax issue, see comment under void menu script.
class menu
{
int32 rowid;
string menu_type;
string name;
int8 unit_label;
int32 decimals;
int32 min;
int32 max;
int32 increment;
bool loop;
int8 advanced;
string[] text_list;
}
void $menu script$ ()
{
menu[] main_menu;
//How do we initialize main_menu with data?
}
I can do
main_menu[0].rowid = 1;
but I was looking to initialize it with something more like
{
{0,"numerical","setpoint1","ohms",1,0,100,1,true,0,""},
{1,"numerical","setpoint2","ohms",1,0,100,1,true,0,""},
{2,"numerical","setpoint3","ohms",1,0,100,1,true,0,""},
{3,"numerical","setpoint4","ohms",1,0,100,1,true,0,""}
}
If this was C# I would be looking to create a list of class objects, or something like the following.
public class RandomData
{
public string Data1 { set; get; }
public string Data2 { set; get; }
public string Data3 { set; get; }
}
List<RandomData> data = new List<RandomData>
{
new RandomData(){ Data1 = 1, Data2 = 2, Data3 = 3 },
new RandomData(){ Data1 = 4, Data2 = 5, Data3 = 6 },
new RandomData(){ Data1 = 7, Data2 = 8, Data3 = 9 }
};
Working on some menu's in Angelscript.
Trying to create a class that in some ways mimics the functionality of the MPC-20 and MPC-10 menu system, right now I am just working on data types and filling the initial list of classes with data, with functions within the class to follow.
I believe I am having a syntax issue, see comment under void menu script.
class menu
{
int32 rowid;
string menu_type;
string name;
int8 unit_label;
int32 decimals;
int32 min;
int32 max;
int32 increment;
bool loop;
int8 advanced;
string[] text_list;
}
void $menu script$ ()
{
menu[] main_menu;
//How do we initialize main_menu with data?
}
I can do
main_menu[0].rowid = 1;
but I was looking to initialize it with something more like
{
{0,"numerical","setpoint1","ohms",1,0,100,1,true,0,""},
{1,"numerical","setpoint2","ohms",1,0,100,1,true,0,""},
{2,"numerical","setpoint3","ohms",1,0,100,1,true,0,""},
{3,"numerical","setpoint4","ohms",1,0,100,1,true,0,""}
}
If this was C# I would be looking to create a list of class objects, or something like the following.
public class RandomData
{
public string Data1 { set; get; }
public string Data2 { set; get; }
public string Data3 { set; get; }
}
List<RandomData> data = new List<RandomData>
{
new RandomData(){ Data1 = 1, Data2 = 2, Data3 = 3 },
new RandomData(){ Data1 = 4, Data2 = 5, Data3 = 6 },
new RandomData(){ Data1 = 7, Data2 = 8, Data3 = 9 }
};
Kyle Bruneau
Applications Engineer - MurCal Inc
Applications Engineer - MurCal Inc
- boyce
- Enovation Controls Development
- Posts: 322
- Joined: Wed Sep 08, 2010 5:09 pm
Re: Angelscript - Initialization of List of Classes
It doesn't look like Angelscript supports initialization lists for classes. It is possible to make a method that assigns values.
PowerVision 2.9 Patch 1 has been updated to the latest version of Angelscript which has better class support. The plan is to have Patch 1 available by the end of June.
Code: Select all
class menu
{
int32 rowid;
string menu_type;
string name;
int8 unit_label;
int32 decimals;
int32 min;
int32 max;
int32 increment;
bool loop;
int8 advanced;
string[] text_list;
void set_menu(int32 rowid, string menu_type, string name)
{
this.rowid = rowid;
this.menu_type = menu_type;
this.name = name;
}
}
void $menu script$ ()
{
menu[] main_menu(3);
//How do we initialize main_menu with data?
main_menu[0].rowid = 1;
main_menu[0].set_menu(0, "numerical", "setpoint1");
main_menu[1].set_menu(1, "numerical", "setpoint2");
main_menu[2].set_menu(2, "numerical", "setpoint3");
}
Boyce Schrack
Enovation Controls
Enovation Controls
- Ocelot
- Posts: 77
- Joined: Thu Oct 06, 2011 10:43 am
Re: Angelscript - Initialization of List of Classes
Boyce,
This will work, I really appreciate it.
This will work, I really appreciate it.
Kyle Bruneau
Applications Engineer - MurCal Inc
Applications Engineer - MurCal Inc
- Ocelot
- Posts: 77
- Joined: Thu Oct 06, 2011 10:43 am
Re: Angelscript - Initialization of List of Classes
Hi,
Another question, I was attempting to do something like the following thread, but assigning the variableIDs into an uint array rather than a uint variable.
viewtopic.php?f=7&t=1420&p=4071&hilit=variableIDs#p4071
I seem to be having some issues with assignment.
snippet of non working angelscript,
numbers_assigned is being called as follows,
I noticed that if I edit numbers_assigned I can assign it to a uint variable, and print it to the debug window, but not an indexed array value
Some suggestions would be appreciated.
Another question, I was attempting to do something like the following thread, but assigning the variableIDs into an uint array rather than a uint variable.
viewtopic.php?f=7&t=1420&p=4071&hilit=variableIDs#p4071
I seem to be having some issues with assignment.
snippet of non working angelscript,
Code: Select all
class menu_variables
{
uint[] numbers_assigned(uint[] numbers)
{
//Cannot seem to assign VariableIDs to array?
numbers[0] = VariableIDs.MB1_one;
numbers[1] = VariableIDs.MB1_two;
numbers[2] = VariableIDs.MB1_three;
numbers[3] = VariableIDs.MB1_four;
numbers[4] = VariableIDs.MB1_five;
return numbers;
}
//Have not tested this yet
float[] numbers_update_read(float[] num, uint[] numbers)
{
uint index = 0;
while(index <= numbers.length())
{
smRead(numbers[index],num[index]);
index++;
}
return num;
}
//Have not tested this yet
float[] numbers_update_write(float[] num, uint[] numbers)
{
uint index = 0;
while(index <= numbers.length())
{
smWrite(numbers[index],num[index]);
index++;
}
return num;
}
}
Code: Select all
void $Menu Init$ ()
{
uint[] numbers;
//Create an object from class for variable read/write access
menu_variables var;
//Get the number VariableIDs listing
var.numbers_assigned(numbers);
}
Code: Select all
uint[] numbers_assigned(uint[] numbers)
{
uint varid = VariableIDs.MB1_one;
PrintNumber(varid); // this assigns and prints the variableID value.
//Cannot seem to assign VariableIDs to array?
numbers[0] = VariableIDs.MB1_one;
numbers[1] = VariableIDs.MB1_two;
numbers[2] = VariableIDs.MB1_three;
numbers[3] = VariableIDs.MB1_four;
numbers[4] = VariableIDs.MB1_five;
return numbers;
}
Kyle Bruneau
Applications Engineer - MurCal Inc
Applications Engineer - MurCal Inc
- boyce
- Enovation Controls Development
- Posts: 322
- Joined: Wed Sep 08, 2010 5:09 pm
Re: Angelscript - Initialization of List of Classes
Looks like if you pre allocate the array it will work.
Code: Select all
uint[] numbers(5);
Boyce Schrack
Enovation Controls
Enovation Controls
- Ocelot
- Posts: 77
- Joined: Thu Oct 06, 2011 10:43 am
Re: Angelscript - Initialization of List of Classes
Boyce,
Pre-allocation of the array took care of the problem
Thank you.
Pre-allocation of the array took care of the problem
Thank you.
Kyle Bruneau
Applications Engineer - MurCal Inc
Applications Engineer - MurCal Inc
- Ocelot
- Posts: 77
- Joined: Thu Oct 06, 2011 10:43 am
Re: Angelscript - Initialization of List of Classes
Additional Question,
When accessing a CharArray in a list, does the following apply?
List Definition
Name: list_one
RowID (int)
header (CharArray)
value (float)
Again, thank you for all the help, I don't seem to be having an issue with data.WriteString(), but I am with data.ReadString().
When accessing a CharArray in a list, does the following apply?
List Definition
Name: list_one
RowID (int)
header (CharArray)
value (float)
Code: Select all
int selected_menu_item = 0;
string selected_menu_title = " ";
CustomListData data;
//Read in the user selected value
smRead(VariableIDs.Number_Selected, selected_menu_item);
//Lookup the row in the table based on the selected index value, assign the information to data
ListManagerGetItem(ListDataType.list_one, selected_menu_item, data);
//Assign the text string to a variable and write it out to the display page
selected_menu_title = data.ReadString(CustomListColumn.list_one_header );
cultureSetString(StringIDs.SelectedMenuTitle, selected_menu_title, true);
Kyle Bruneau
Applications Engineer - MurCal Inc
Applications Engineer - MurCal Inc
- boyce
- Enovation Controls Development
- Posts: 322
- Joined: Wed Sep 08, 2010 5:09 pm
Re: Angelscript - Initialization of List of Classes
Just from looking at the code, have you tried the ReadString syntax like this?
I don't know if it's the same as what you have.
Code: Select all
data.ReadString(CustomListColumn.list_one_header, selected_menu_title);
Boyce Schrack
Enovation Controls
Enovation Controls
- ronaldbroth
- Posts: 15
- Joined: Wed Jun 14, 2017 12:45 pm
Re: Angelscript - Display Menu
Good morning,
This is probably not the best place to ask this question but this topic had to do with Angelscript and also menus so here we go. WARNING: I am a rookie PV writer so the question I am asking is basic.
I just want to know if I can select/display a specific PAGE via Angelscript.
I have done it so far via Activity Program and assigning UIApp -> ShowView(Main Layer.P15) to a Fire Actions box. I have 26 PAGES so this gets a little long and the way I am determining what PAGE to selected is being done via Angelscript so it would be easier to make it part of the Script program.
Thanks
Ron Roth
This is probably not the best place to ask this question but this topic had to do with Angelscript and also menus so here we go. WARNING: I am a rookie PV writer so the question I am asking is basic.
I just want to know if I can select/display a specific PAGE via Angelscript.
I have done it so far via Activity Program and assigning UIApp -> ShowView(Main Layer.P15) to a Fire Actions box. I have 26 PAGES so this gets a little long and the way I am determining what PAGE to selected is being done via Angelscript so it would be easier to make it part of the Script program.
Thanks
Ron Roth
- boyce
- Enovation Controls Development
- Posts: 322
- Joined: Wed Sep 08, 2010 5:09 pm
Re: Angelscript - Initialization of List of Classes
I had to find out, but it is done like this:
It's done by sending the Show Page action to the UIApp with the page view to show.
Code: Select all
//---------------------------------------------------------------------------------------------
// Murphy Scripting
// - Leave EventName as $Show Page$ for main script method
//---------------------------------------------------------------------------------------------
void $Show Page$ ()
{
SendAction(ApplicationIDs.UIApp, ActionIDs.UIApp_Show_View, PageViewIDs.Main_Layer_Main_Page_View_2);
}
Boyce Schrack
Enovation Controls
Enovation Controls