[Solved] Persistent var between two manialinks ?

You can talk about ManiaScript for ManiaPlanet here

Moderator: English Moderator

Post Reply
BusardCendre
Posts: 174
Joined: 30 May 2013, 09:40

[Solved] Persistent var between two manialinks ?

Post by BusardCendre »

Hi all,

I'm actually working on a little title pack
and I have a little problem : I need to get a variable from a manialink to another ...
In fact, in a custom solo mode,
according to the guy you choose in the mappers page,
the maps page will be build with his maps.
I'm not sure you understood, if not : just remember I need a persistent data between two manialink ;)

from what I saw here
https://forum.maniaplanet.com/viewtopic ... 89#p271789
and here
https://forum.maniaplanet.com/viewtopic ... 45#p268945
it seems to be possible ...

here is what I've written in first file :

Code: Select all

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<manialink version="2">
    <label id="Busard" text="Busard" scriptevents="1" manialink="file://Media/Manialinks/TrackMania/VioK_Tests/VioK_Maps.xml"/>
    <label id="KriTtPen" text="KriTtPen" scriptevents="1" manialink="file://Media/Manialinks/TrackMania/VioK_Tests/VioK_Maps.xml"/>

<script><!--	
	#RequireContext CMlScript	
	***StartManialink***
	***
	declare persistent Text Persistent_VioKTM_ChosenMapper for LocalUser;
	***
 	
	***Yield***
	***
	foreach (Event in PendingEvents) {
		if (Event.Type == CMlEvent::Type::MouseClick) {
			if (Event.ControlId == "Busard") {
				Persistent_VioKTM_ChosenMapper = "Busard";
			}
			if (Event.ControlId == "KriTtPen") {
				Persistent_VioKTM_ChosenMapper = "KriTtPen";
			}
		}
	}
	***

   main() {
	---StartManialink---						
	    while (True) {
		    yield;
        	---Yield---					
        }
    }
--></script>
</manialink>

And in the second file :

Code: Select all

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<manialink version="2">
<script><!--		
    #RequireContext CMlScript 

    #Const C_MapperNames        ["Busard", "KriTtPen"]   // short list for tests =)

    ***StartManialink***
    ***			
        declare persistent Text Persistent_VioKTM_ChosenMapper for LocalUser;
        if (Persistent_VioKTM_ChosenMapper != "") {
            G_ChosenMapper = Persistent_VioKTM_ChosenMapper;	
            foreach (Mapper in C_MapperNames) {
                if (G_ChosenMapper == Mapper) {
                      DisplayMainPage();
                }
            }
        }
    ***
    ***Yield***
    ***
    // thing to be done when choosing a map ...
    ****

    DisplayMainPage() {
        // things to display according to mapper's name
    }

    main() {
        ---StartManialink---						
             while (True) {
                yield;
                ---Yield---					
            }
   }
--></script>
</manialink>
I know I could do only one manialink instead of two to get the same result ...
but I think I will need later to get another persistent variable between two manialniks, so ...

Thanks for help =)
Last edited by BusardCendre on 20 Sep 2016, 21:01, edited 1 time in total.
Image

CPU : AMD FX-4170 (4 CPUs, ~4.2 GHz)
GPU : Sapphire Radeon HD 7850, 2 Go , DX 11
RAM : 8 Go DDR3
Win 7 Ultimate x64
User avatar
maxi031
Posts: 378
Joined: 17 Jul 2011, 00:55

Re: Persistent var between two manialinks ?

Post by maxi031 »

Persistent data is saved on client pc inside ScriptCache file, so any data you save with it will be client bound and can be reused across multiple manialinks.
My specs:
MOBO: MB AM3+ 970 Gigabyte GA-970A-DS3P
CPU: AM3+ AMD FX-8320E
GPU: Nvidia GeForce GTX750-Ti ASUS 2GB DDR5
RAM: DDR3 8GB 1866MHz Kingston HyperX
SSD: SATA3 120gb SanDisk
OS: Ubuntu 19.04
TY MICMO
User avatar
Dommy
Translator
Translator
Posts: 1901
Joined: 25 Aug 2011, 21:45
Location: Poland
Contact:

Re: Persistent var between two manialinks ?

Post by Dommy »

Declaring variable for LocalUser should make it disable in any manialink. Declaration for Page will only work per single manialink url.
Ryzen 7 2700X, GTX 1070 Ti, 16 GB RAM, Windows 10 Insider Build
FORUM MODERATOR • CREATOR OF SHOOTMANIA GALAXY & TRACKMANIA² PURSUIT

Contact me via GALAXY & PURSUIT DISCORD
BusardCendre
Posts: 174
Joined: 30 May 2013, 09:40

Re: Persistent var between two manialinks ?

Post by BusardCendre »

Thanks a lot !!
I found it =)

the problem was I had a manialink attribute in my <label>.
When the label was clicked,
the "OnMouseClick" section of the script wasn't working,
I saw it with adding a log in it ;)

a strange thing is that :

Code: Select all

OpenLink("file://Media/Manialinks/TrackMania/VioK_Tests/VioK_Maps.xml", CMlScript::LinkType::Goto);
doesn't work in Interface Desiger, but works fine in the title pack.

Declaring variable for LocalUser is the only way I found to make it work in Interface Designer :
CGameManialinkPage doesn't support declaration of Persistent attribute for Page
and CGameManialinkScriptHandler doesn't support declaration of Persistent attribute at all.

Dommy, you're really a magician !!
this time you solved my prob without telling me where the error was. :mrgreen:
Image

CPU : AMD FX-4170 (4 CPUs, ~4.2 GHz)
GPU : Sapphire Radeon HD 7850, 2 Go , DX 11
RAM : 8 Go DDR3
Win 7 Ultimate x64
User avatar
Dommy
Translator
Translator
Posts: 1901
Joined: 25 Aug 2011, 21:45
Location: Poland
Contact:

Re: [Solved] Persistent var between two manialinks ?

Post by Dommy »

Pro tip: never use interface designer
Ryzen 7 2700X, GTX 1070 Ti, 16 GB RAM, Windows 10 Insider Build
FORUM MODERATOR • CREATOR OF SHOOTMANIA GALAXY & TRACKMANIA² PURSUIT

Contact me via GALAXY & PURSUIT DISCORD
User avatar
Nerpson
Translator
Translator
Posts: 1555
Joined: 27 Sep 2013, 18:02
Location: France
Contact:

Re: [Solved] Persistent var between two manialinks ?

Post by Nerpson »

Pro tip+: Never use the interface designer if you do not edit the xml after.
ImageImageImageImage
BusardCendre
Posts: 174
Joined: 30 May 2013, 09:40

Re: [Solved] Persistent var between two manialinks ?

Post by BusardCendre »

I really find Interface Designer very usefull :
to see exactly what will look the screen, and to quickly know if I well understood how to write some code.
I know it has some kind of bugs,
I think that the biggest is that ManiaPlanet crashes and close when we forget some part of code :
as I don't know all code by heart, I often need to search in other files or documentation,
it's often at this moment that I loose what I hadn't saved ...
but I think it's not a so bad thing :
the more I write and rewrite some code, the more I remember ;)

Nerpson, could you explain why I should edit the xml file after writing it with Interface Designer ?
the only strange thing I found is that it add some empty lines at the beginning of the file each time I save the file
Image

CPU : AMD FX-4170 (4 CPUs, ~4.2 GHz)
GPU : Sapphire Radeon HD 7850, 2 Go , DX 11
RAM : 8 Go DDR3
Win 7 Ultimate x64
User avatar
Nerpson
Translator
Translator
Posts: 1555
Joined: 27 Sep 2013, 18:02
Location: France
Contact:

Re: [Solved] Persistent var between two manialinks ?

Post by Nerpson »

I do not use the export functionality in it, I always copy/paste in my text editor.
You should always edit the output xml because after some time spent in editing your file, you'll find some extra spaces in tags.
In addition, attributes are not sorted, I prefer having all tags with attributes in this order:

Code: Select all

<tag id="..." class="..." posn="..." sizen="..." scale="..." halign="..." valign="..." style="..." substyle="..." etc />
So to recap, I'm designing UIs in this tool, but I always review the output xml.
ImageImageImageImage
BusardCendre
Posts: 174
Joined: 30 May 2013, 09:40

Re: [Solved] Persistent var between two manialinks ?

Post by BusardCendre »

Thanks

I manually write ids, classes and datas attributes at the begining of tags too =)
but I haven't noticed any extra spaces yet
Image

CPU : AMD FX-4170 (4 CPUs, ~4.2 GHz)
GPU : Sapphire Radeon HD 7850, 2 Go , DX 11
RAM : 8 Go DDR3
Win 7 Ultimate x64
Post Reply

Return to “ManiaScript”

Who is online

Users browsing this forum: No registered users and 0 guests