Notifications
Clear all

[Closed] arg….arrays

a bit frustrated here, with the lack of data types and declarations and compiler error codes!


rollout rc "RC"
(
 global renderc = #()
 
 for o in objects do
 (
  if (stricmp (substring o.name 1 3) "rc_" == 0) then
  (
   renderc insertItem o.name renderc.count+1
  )
 )
 
 listbox lbRenderCache "Render Cache:" renderc
)

just trying to do a simple test here to get started…to make a rollout with a listbox of all items in the scene that have names startign with “rc_”, i get errors all over the place but they seem to be different every time. what am I doing wrong?

6 Replies

rollout rc "RC"
(
global renderc = #() --you could also set to to local
 
listbox lbRenderCache "Render Cache:"
 
on rc open do --this block will be evaluated when the script opens
( 
-- this will collect all the names of the objects that passes the argument of the stricmp
 
renderc = for o in objects where (stricmp (substring o.name 1 3) "rc_" == 0) collect o.name
-- this will now set the list items of the list using the collected array
lbRenderCache.items = renderc
)
 
)
createdialog rc

id also prefer it this way…


rollout rc "RC"
(
local renderc = #()
 
listbox lbRenderCache "Render Cache:"
button refresh_button "Refresh"
 
fn updateList =
(
renderc = for o in objects where (stricmp (substring o.name 1 3) "rc_" == 0) collect o.name
lbRenderCache.items = renderc
)
 
on rc open do updateList()
on refresh_button pressed do updateList()
)
createdialog rc
-- using a function, you could call it again and again on any other handler.

this might work… (i think)

hope this helps!

Without running the code, it looks like syntax errors to me.
First of all, you cannot run code inside a rollout – only in a handler (see Galagast’s reply).
Then, instertItem expects three parameters: The value to be insterted, the array to be inserted in and the location to be inserted at:

[left][b]insertItem <value>  <array> <integer>[/b]

[/left]
[left]Inserts the value at the specified index in the array, growing the array if necessary. Returns OK.
[/left]
In your code, you have the array, then the insertItem command, then the value and then the index + 1 but without brackets, so insertItem still sees 3 argument and not two, and gets very very confused.

The line should look like
  insertItem o.name renderc (renderc.count+1)
Of course, it would be better to use APPEND instead, as it does not requre any indices:
  append renderc o.name
Even better, use a FOR loop with COLLECT just like Galagast suggested :)
Something like
  renderc = for o in objects where matchpattern o.name pattern:"rc_*" collect o.name

Basically what you are trying to do is execute functions within a rollout definition. Which as you’ve found doesn’t work. You need to either set a variable, define controller or define an event. Any functions need to be kept outside the rollout definition or included within a rollout even i.e. ‘on open’

Try this:

function getAllObjsNames =
 	(
 	local renderc = #();
 	 for o in objects as array do
 	 (
 	  if (stricmp (substring o.name 1 3) "rc_" == 0) then
 	  (
 	   append renderc o.name;
 	  );
 	 );
 	 return renderc;
 	);
 	
 rollout rc "RC"
 ( 
  listbox lbRenderCache "Render Cache:" items:(getAllObjsNames());
 );
 
 createDialog rc;

Also you’ll notice I used append rather then insertItem for adding items to the array.

galagast, thanks for your code. I was originally trying to do it with collect, but that is really just syntactic sugar for the basic way, and so I was trying to get the basics down first, you know! I will make sure to learn them both though.

Bobo,

oops…yeah, I knew that it required 3 args, I must have lost one of them when I was copy/pasting/rewriting trying to debug it.

I was going to use append, but the documentation in maxscript did not make it clear that append actually mutated the array, as opposed to returning a new array with the new item appended to the end. now I know…

Impus,

oh, that’s the problem? Ok, I had no idea that there was such a restrictino. I had used event handlers in there before and took that as an indication that “any code goes here.”

Well, thanks all for your help, I’ll try this all out later.

stuh505, I apologize for eating into your thread without any real contribution from my side …

bobo, galagast, a really stupid question from me, but how do u manage to get these scrollable windows within a post where u guyz post scripts?

-shibu

these are called vBcodes…

here are some you could use in cgtalk:
http://www.cgtalk.com/misc.php?do=bbcode

the ones used were –> <code>(put any code here)</code> (use “[ ]” instead of “< >”)
any code inside it will appear inside those boxes
hope this helps:)