[ManiaScript] ValueLineCount not working for maptype scripts

Moderators: w1lla, NADEO

Post Reply
kastun
Posts: 18
Joined: 28 Oct 2012, 10:05

[ManiaScript] ValueLineCount not working for maptype scripts

Post by kastun »

I discovered that MlLabel.ValueLineCount always returns -1 if the manialink is displayed in maptype context.

\Documents\ManiaPlanet\Scripts\MapTypes\ShootMania\Test.Script.txt

Code: Select all

#RequireContext CSmMapType

main() {
	ManialinkText = """
		<manialink version="1">
			<script><!--
			main() { 
				declare CMlLabel MlLabel;
				
				MlLabel = (Page.GetFirstChild("MlLabel") as CMlLabel);

				log("MlLabel line count: " ^ MlLabel.ValueLineCount);
			}
			--></script>
			<timeout>0</timeout>
			<label id="MlLabel" posn="0 0 3" sizen="150 10" halign="center" valign="center" text="Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet." autonewline="1" />
		</manialink>
	""";

	while(True) {
		yield;
	}
}
If the same manialink code is opended with the manialink explorer the correct result is returned.

EDIT:
If changing the text on the label with SetText() the ValueLineCount is not changed.
This is also the case if not in maptype context.
kastun
Posts: 18
Joined: 28 Oct 2012, 10:05

Re: [ManiaScript] ValueLineCount in maptype script

Post by kastun »

Just found out by testing again: The ValueLineCount gets only updated if you yield;.
So as workaround simply yield before you get the ValueLineCount and you will not have a problem with -1 in maptype context. EDIT: This is only working if the label is visible!

Regarding the edit of my last post:
Also here yield; after SetText() is the solution to get the updated ValueLineCount.

For reproducing create the following files.
With using this Test.Script.txt as gamemode for editing a map in shootmania you get the -1 bug.
With loading file://Media/Manialinks/test/lineCount.xml in the manialink browser you get the right value without yield.

\Documents\ManiaPlanet\Scripts\MapTypes\ShootMania\Test.Script.txt

Code: Select all

#RequireContext CSmMapType

main() {
	declare MyIncludeLayer = UILayerCreate(); 
	MyIncludeLayer.ManialinkPage = "file://Media/Manialinks/test/lineCount.xml"; 

	while(True) {
		yield;
	}
}
\Documents\ManiaPlanet\Media\Manialinks\test\lineCount.xml

Code: Select all

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<manialink version="1">
	<script><!--
	main() { 
		declare CMlLabel MlLabel;
		declare CMlLabel MlResult;
		
		MlLabel = (Page.GetFirstChild("MlLabel") as CMlLabel);
		MlResult = (Page.GetFirstChild("MlResult") as CMlLabel);
		MlResult.SetText(MlResult.Value ^ "\nInitialised CMlLabels");
		MlResult.SetText(MlResult.Value ^ "\n'No yield' ValueLineCount: " ^ MlLabel.ValueLineCount ^ " ('Lore ipsum' text)");

		MlResult.SetText(MlResult.Value ^ "\nUsing yield;");
		yield;

		MlResult.SetText(MlResult.Value ^ "\nCorrect ValueLineCount: " ^ MlLabel.ValueLineCount ^ " ('Lore ipsum' text)");
		MlResult.SetText(MlResult.Value ^ "\nwaiting 5 seconds ...\n");
		sleep(5000);
		MlLabel.SetText("Short Text, changed after 5 seconds. Reload for original long text. See test results listed at the bottom of the page.");
		MlResult.SetText(MlResult.Value ^ "\nSet short text to the label.");
		MlResult.SetText(MlResult.Value ^ "\nNew ValueLineCount: " ^ MlLabel.ValueLineCount ^ " ('Short text' text)");
		yield;
		MlResult.SetText(MlResult.Value ^ "\nUsing yield; after setting the text.");
		MlResult.SetText(MlResult.Value ^ "\nNew ValueLineCount: " ^ MlLabel.ValueLineCount ^ " ('Short text' text)");
	}
	--></script>
	<timeout>0</timeout>
	<label id="MlLabel" posn="0 45 3" sizen="150 10" halign="center" valign="center" text="Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet." autonewline="1" />
	<label id="MlResult" posn="-75 10 3" sizen="150 10" halign="top" valign="left" text="History:" autonewline="1" />
</manialink>
Post Reply

Return to “Maniaplanet Reports”

Who is online

Users browsing this forum: No registered users and 0 guests