You are not logged in.

milotimbol

Intermediate

  • "milotimbol" started this thread

Posts: 233

Location: Philippines

Occupation: Software Developer

  • Send private message

1

Sunday, February 26th 2023, 1:10pm

Array is null after loadscene

Hi all, I declare custom xml elements to manage the menu of my tours like the one below.

Source code

1
2
3
4
5
6
7
8
9
	<scene_group name="name">
		<scene name="scene_1" />
		<scene name="scene_2" />
		<scene name="scene_3" />
		<scene name="scene_4" />
		<scene name="scene_5" />
		<scene name="scene_6" />
		<scene name="scene_7" />
	</scene_group>


I am able to loop through the content.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
	<action name="skin_build_scene_groups">

		for(set(counter,0), counter LT scene_group.count, inc(counter),	

			set(group_id, get(scene_group[get(counter)].name) );	
			set(scenes_count, get(scene_group[get(counter)].scene.count) );	


			for(set(scene_counter,0), scene_counter LT scene_group[get(counter)].scene.count, inc(scene_counter),	
			

				set(scene_name, get(scene_group[get(counter)].scene[get(scene_counter)].name) );
<!-- do something here-->
				

			);
		);
	</action>


However the code above will only work before any "loadscene" calls, after loadscene it no longer works and when I try to do a check for the count its null

Source code

1
trace(*scene_group.count);


The debug code above when put before loadscene returns a number but after loadscene it returns null.

Trying to go through the docs and cant find an explanation. Can anyone enlighten me on what is happening?

2

Sunday, February 26th 2023, 1:25pm

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<group name="group_1">
	<scene name="scene_1" />
	<scene name="scene_2" />
	<scene name="scene_3" />
	<scene name="scene_4" />
	<scene name="scene_5" />
	<scene name="scene_6" />
	<scene name="scene_7" />
</group>

<action name="build_groups" scope="local">
	trace("active scene = ",xml.scene);
	for(set(local.i,0), i LT group.count, inc(i),
		for(set(local.j,0), j LT group[get(i)].scene.count, inc(j),
			copy(local.name, group[get(i)].scene[get(j)].name);
			trace(name);
		);
	);
</action>

<events name="test" onnewscene="build_groups()" keep="true" />

this works without problem also after scene changes
maybe it is this ... get(scene_group[get(counter)].scene[get(scene_counter)].name)
i would avoid nesting too many get() calls

also in general..
- set(x, get(y)) is easier/better done by copy(x, y)
- use local scopes! with global variables like "counter" in multiple functions you easily run into problems

milotimbol

Intermediate

  • "milotimbol" started this thread

Posts: 233

Location: Philippines

Occupation: Software Developer

  • Send private message

3

Monday, February 27th 2023, 12:37am

Thanks for the tip, will apply it in future code that I write. However my question is in general why is the object null after loadscene? See code below.

Source code

1
2
3
trace("group count is = ", *group.count); <!-- returns a number -->
loadscene(get(scene[%1].name), null, MERGE|KEEPVIEW, OPENBLEND(0.5, 0.0, 0.75, 0.05, linear) );
trace("group count is = ", *group.count);<!-- returns null -->


So I have many of these groups by the way

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<group name="group_1a">
	<scene name="scene_1" />
	<scene name="scene_2" />
	<scene name="scene_3" />
	<scene name="scene_4" />
	<scene name="scene_5" />
	<scene name="scene_6" />
	<scene name="scene_7" />
</group>
<group name="group_1b">
	<scene name="scene_1b" />
	<scene name="scene_2b" />
	<scene name="scene_3b" />
	<scene name="scene_4b" />
	<scene name="scene_5b" />
	<scene name="scene_6b" />
	<scene name="scene_7b" />
</group>


Is there a specific reason for this? Cant seem to find it in the documentation.

milotimbol

Intermediate

  • "milotimbol" started this thread

Posts: 233

Location: Philippines

Occupation: Software Developer

  • Send private message

4

Monday, February 27th 2023, 12:51am

Oh shit Im stupid you are right I messed up my variables overriding the object. Thanks for the tip it lead me to the right direction!