LScript Help!

jboudreau

Super Member
Hi Guys

I'm just teaching my self some lscript and going through some examples. When I use the following example below I get an error on line 44

@version 2.1
@warnings

c1..3;
lb_items;

main
{
for(x = 1;x <= 10;x++)
lb_items += "Item_" + x;
reqbegin("Testing List Box");

c1 = ctllistbox("Items",300,300,"lb_count","lb_name");
c2 = ctlbutton("Add",200,"add_button");
c3 = ctlbutton("Delete",200,"del_button");

reqpost();
}

lb_count
{
// don’t use size() here because that counts
// all elements, even if they have ‘nil’.

return(lb_items.count());
}

lb_name: index
{
return(lb_items[index]);
}

add_button
{
lb_items += "Item_" + (lb_items.size() + 1);
setvalue(c1,lb_items.count());
requpdate();
}

del_button
{
sel = getvalue(c1);

lb_items[sel] = nil;
lb_items.pack();
lb_items.trunc();
setvalue(c1,lb_items.count());
requpdate();
}

This line here lb_items[sel] = nil; (when the delete button is pressed I get this error message "Line 44, illegal data type used for array index"
I'm not sure why I get this error since it was a code I copied directly out of the lscript manual

Any help would be great

Thanks,
Jason
 

jboudreau

Super Member
Sel is expected to be an integer. So you're passing something other than an integer right now.

okay, do you know how to fix it?

I know if I write lb_items[1] = nil; then the delete button works but once it deletes all 10 items I get this error message on this line

setvalue(c1,lb_items.count());


line 47, invalid argument 2 value to setvalue()

Thanks,
Jason
 
Last edited:

ernpchan

Active member
Try this:

Code:
@version 2.1
@warnings
@name Temp

c1..3;
lb_items;
choice;

main
{
for(x = 1;x <= 10;x++)
lb_items += "Item_" + x;
reqbegin("Testing List Box");

c1 = ctllistbox("Items",300,300,"lb_count","lb_name","lst_event");
c2 = ctlbutton("Add",200,"add_button");
c3 = ctlbutton("Delete",200,"del_button");

reqpost();
}

lb_count
{
// don’t use size() here because that counts
// all elements, even if they have ‘nil’.

return(lb_items.count());
} 

lb_name: index
{
return(lb_items[index]);
}

add_button
{
lb_items += "Item_" + (lb_items.size() + 1);
setvalue(c1,lb_items.count());
requpdate();
}

del_button
{
	lst_event(items);
	//sel = getvalue(c1);
	lb_items[choice] = nil;
	lb_items.pack();
	lb_items.trunc();
	setvalue(c1,lb_items.count());
	requpdate();
}

lst_event: items
{
	// 'items' will be received from listbox as an array of integer index values, or 'nil'

	if(items == nil)
	{
		// do nothing 
	}
	else
	{
		choice = integer(items[1]);
		return (choice);
	}
	selectedListItems = items;
}
 

jboudreau

Super Member
thank you again for all your help. I'm still getting that invalid argument 2 value to set value() and I have no idea what it means
 
Last edited:

lwpop

New member
jboudreau did you solve your ctllistbox issues? global variables help. Also, timing on when certain UI objects are created and when the events fire sometimes require extra if then checks.

If you are still having trouble, I might have an example which could help. I know Lscript is frustrating - but unfortunately, we have all struggled with it, and sadly, a comprehensive knowledge of it is all obscure, arcane thoughts floating spread out among a handful of heads in the world...
 
Top Bottom