Angelscript - Initialization of List of Classes

Discuss issues and ideas you have to configuring displays with PowerVision
Ocelot
Posts: 77
Joined: Thu Oct 06, 2011 10:43 am

Angelscript - Initialization of List of Classes

Post by Ocelot » Mon Jun 19, 2017 5:07 pm

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 }
};
Kyle Bruneau
Applications Engineer - MurCal Inc
boyce
Enovation Controls Development
Enovation Controls Development
Posts: 322
Joined: Wed Sep 08, 2010 5:09 pm

Re: Angelscript - Initialization of List of Classes

Post by boyce » Tue Jun 20, 2017 11:35 am

It doesn't look like Angelscript supports initialization lists for classes. It is possible to make a method that assigns values.

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");
}
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.
Boyce Schrack
Enovation Controls
Ocelot
Posts: 77
Joined: Thu Oct 06, 2011 10:43 am

Re: Angelscript - Initialization of List of Classes

Post by Ocelot » Tue Jun 20, 2017 2:52 pm

Boyce,

This will work, I really appreciate it.
Kyle Bruneau
Applications Engineer - MurCal Inc
Ocelot
Posts: 77
Joined: Thu Oct 06, 2011 10:43 am

Re: Angelscript - Initialization of List of Classes

Post by Ocelot » Wed Jun 21, 2017 1:56 pm

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,

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;
	}
}
numbers_assigned is being called as follows,

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);
}
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

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;
	}
Some suggestions would be appreciated.
Kyle Bruneau
Applications Engineer - MurCal Inc
boyce
Enovation Controls Development
Enovation Controls Development
Posts: 322
Joined: Wed Sep 08, 2010 5:09 pm

Re: Angelscript - Initialization of List of Classes

Post by boyce » Wed Jun 21, 2017 2:54 pm

Looks like if you pre allocate the array it will work.

Code: Select all

   uint[] numbers(5);
Boyce Schrack
Enovation Controls
Ocelot
Posts: 77
Joined: Thu Oct 06, 2011 10:43 am

Re: Angelscript - Initialization of List of Classes

Post by Ocelot » Wed Jun 21, 2017 3:01 pm

Boyce,

Pre-allocation of the array took care of the problem

Thank you.
Kyle Bruneau
Applications Engineer - MurCal Inc
Ocelot
Posts: 77
Joined: Thu Oct 06, 2011 10:43 am

Re: Angelscript - Initialization of List of Classes

Post by Ocelot » Mon Jul 03, 2017 3:35 pm

Additional Question,

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);
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().
Kyle Bruneau
Applications Engineer - MurCal Inc
boyce
Enovation Controls Development
Enovation Controls Development
Posts: 322
Joined: Wed Sep 08, 2010 5:09 pm

Re: Angelscript - Initialization of List of Classes

Post by boyce » Thu Jul 06, 2017 10:36 am

Just from looking at the code, have you tried the ReadString syntax like this?

Code: Select all

data.ReadString(CustomListColumn.list_one_header, selected_menu_title);
I don't know if it's the same as what you have.
Boyce Schrack
Enovation Controls
ronaldbroth
Posts: 15
Joined: Wed Jun 14, 2017 12:45 pm

Re: Angelscript - Display Menu

Post by ronaldbroth » Mon Jul 17, 2017 11:37 am

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
boyce
Enovation Controls Development
Enovation Controls Development
Posts: 322
Joined: Wed Sep 08, 2010 5:09 pm

Re: Angelscript - Initialization of List of Classes

Post by boyce » Mon Jul 17, 2017 1:43 pm

I had to find out, but it is done like this:

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);
}
It's done by sending the Show Page action to the UIApp with the page view to show.
Boyce Schrack
Enovation Controls