Author Topic: XML help  (Read 3701 times)

Motley

  • Full Member
  • ***
  • Posts: 253
  • Karma: +32/-34
    • View Profile
XML help
« on: August 18, 2016, 07:38:25 am »
http://liberty-unleashed.co.uk/LUWiki/Squirrel/Tutorials

I really, really would like to think this is a bug, Could sugarD pm Vrocker to see if there is something going on with the xml tutorial?

:P I'm hoping there will be one like the sq lite tutorial.
If not I plan to make one and have more eyes view it to professionalize it.


EDITED
Okay I have really been studying Extensible Markup Language (xml), I am trying to understand the different wording in the lu wiki "broken wiki links are not helping", I am trying to create a simple account system, If someone could lead me to get the name of the player where I saved the player that would be helpful.

Example of the current layout:

Code: [Select]
<Players>
    <Accounts>
        <liberty Name="Jeff" Money="20" Skin="14" Health="50" />
        <liberty Name="Donald" Money="14" Skin="33" Health="45" />
        <liberty Name="Frank" Money="47" Skin="1" Health="95" />
    </Accounts>
</Players>

So if I could figure out a way to get the name where player.Name = Name, Then I am very close to getting threw this more "Speeding me threw".

I have a dumb feeling I need to do something similar to an xml 'Entity',

And for in LU I think that might be XmlElement.Text
And that description for lu can be found at http://liberty-unleashed.co.uk/libertywiki/index.php?title=Squirrel/Server/Functions/XmlElement/Text&action=edit&redlink=1
***Broken link**
 

I think I am doing this all wrong, At another time I am going to do something more of

Code: [Select]
<Jeff>
    <Account>
        <liberty Money="20" Skin="14" Health="50" />
    </Account>
</Jeff>

This should solve my issue..

Tried. Doesn't update...
« Last Edit: August 19, 2016, 09:46:14 pm by Mötley »

Ankris

  • Full Member
  • ***
  • Posts: 110
  • Karma: +29/-44
    • View Profile
Re: XML help
« Reply #1 on: August 20, 2016, 12:51:27 am »
element.GetAttribute("Name");

Also you shouldn't use XML because there is no way to close the file.

Motley

  • Full Member
  • ***
  • Posts: 253
  • Karma: +32/-34
    • View Profile
Re: XML help
« Reply #2 on: August 20, 2016, 04:51:22 am »
I noticed this with not being capable with closing the file, I have used http://liberty-unleashed.co.uk/LUWiki/Squirrel/Server/Functions/HashTables/Close And I didnt recieve and error. I also removed that as I thought it was stupid and probably wasn't actually working, Maybe you could put input into that,.

Also I tried that with the original version but it didn't work, I thought it was that simple as well,

Code: [Select]
local iName = element.GetAttribute("Name");
if ((iName) == Player.Name ) {

I even tried
Code: [Select]
local iName = element.GetAttribute("Name");
while ((iName) == Player.Name ) {

This didn't do the job before. But it's worth trying more,.



Edit okay I know my code is going to move around like crazy
"some reason the internet does that when you pres tab 'I do it in notepad 24 7 '"

My play around code

Code: [Select]
//----------------------------------------------------------------------------------------------------------------------
//Accounts
function onPlayerPart(player, reason)
{
local XmlDoc = XmlDocument( "Accountlist.xml" );

if ( XmlDoc.LoadFile() )
{
local xmlRoot = XmlElement( "Players" );
local xmlLocationsRoot = XmlElement( "Accounts" );
local xmlClass = XmlElement( "Liberty" );
local name = xmlClass.GetAttribute( "Name" );

if (  name ) {
if (name == player.Name) {



local xmlClass = XmlElement( "Liberty" );
xmlClass.SetAttribute( "Name", player.Name );
xmlClass.SetAttribute( "Skin", player.Skin );
xmlClass.SetAttribute( "Cash", player.Cash );
xmlClass.SetAttribute( "Kills", player.Score );

xmlLocationsRoot.LinkChild( xmlClass );
xmlRoot.LinkChild( xmlLocationsRoot );
XmlDoc.LinkChild( xmlRoot );
XmlDoc.SaveFile();
}
}
XmlDoc.SaveFile();
}
else
{
/* Player has never joined, Create a new entry */
local xmlRoot = XmlElement( "Players" );
local xmlLocationsRoot = XmlElement( "Accounts" );

local xmlClass = XmlElement( "Liberty" );
xmlClass.SetAttribute( "Name", player.Name );
xmlClass.SetAttribute( "Skin", player.Skin );
xmlClass.SetAttribute( "Cash", player.Cash );
xmlClass.SetAttribute( "Kills", player.Score );

xmlLocationsRoot.LinkChild( xmlClass );

xmlRoot.LinkChild( xmlLocationsRoot );
XmlDoc.LinkChild( xmlRoot );
XmlDoc.SaveFile();
}
}


function onPlayerJoin(player) {
local xmlRoot = XmlElement( "Players" );
local xmlLocationsRoot = XmlElement( "Accounts" );
local xmlClass = XmlElement( "Liberty" );
local name = xmlClass.GetAttribute( "Name" );

if ( name ) {
if (name == player.Name) {


local skin = xmlClass.GetAttribute( "Skin" );
local cash = xmlClass.GetAttribute( "Cash");
local kills = xmlClass.GetAttribute( "Kills" );

xmlLocationsRoot.LinkChild( xmlClass );
Message("NOTHING EVER HAPPENS HEAR!!!!!", player);//Just a test

player.Skin = skin;
player.Cash = cash;
player.Score = kills;
}
}
}
« Last Edit: August 20, 2016, 08:20:30 am by Mötley »

Ankris

  • Full Member
  • ***
  • Posts: 110
  • Karma: +29/-44
    • View Profile
Re: XML help
« Reply #3 on: August 20, 2016, 08:19:24 am »
Code: [Select]
if (command == "banlist") {
    local list = XmlDocument();
    list.LoadFile("banlist.xml");
       
    local element = list.FirstChild().FirstChild();
    local i = 0;

    while (element != null) {
    local no_name = false;
      local ip = element.GetAttribute("ip"), name = element.GetAttribute("name"), uid = element.GetAttribute("luid");
      local reason = ReadIniString(DATA_PATH+"bans.ini", "reason", uid);
      if (reason == "") reason = " Unknown";
        if (name == "0") no_name = true;

      if (!no_name) MessagePlayer("ID "+i+" | Name: "+name+" ("+ip+") | Reason:"+reason, player, White);
      else MessagePlayer("ID "+i+" | UID: "+uid+" ("+ip+") | Reason:"+reason, player, White);

      element = element.NextSibling();
      i ++;
    }

    if (i == 0) return MessagePlayer("No bans", player, Red);
    return true;
  }

Motley

  • Full Member
  • ***
  • Posts: 253
  • Karma: +32/-34
    • View Profile
Re: XML help
« Reply #4 on: August 22, 2016, 09:23:49 pm »
It's impossible.

The data will always write to the xml file regardless.
Even if you were to save/load the file as say Motley.xml You will still have errors with above ^ "many saves".

I even attempted to clear the file, more errors on writing the children. Even attempted wb+. Didn't help.

For some reason when getting one of the children on print you will always select the top save not an search for the player.Name



We need a way to select cash, deaths, level etc in the same style as sq lite.
With the ability to overwrite a xmlelement save "not doubling, tripling etc".

I know Xml is not intended to look pretty but I can guarantee this would be the most liked method I have ever used if it's ever updated.

For anyone wanting to study xml hear is a good link for you http://www.tizag.com/xmlTutorial/index.php

At that note if the format would return like so then there would not be an issue,. I have used "Player.Name" for Student and the next player that saves there account the next child for "Player.Name" returns an error when creating. Why??? no clue "Seems LU only wants to work with the same output for the xml file rather than adding more children", I blame the source as well partial not fully 100% understanding xml .


Code: [Select]
<class_list>
<student>
<name>Robert</name>
<grade>A+</grade>
</student>
<student>
<name>Lenard</name>
<grade>A-</grade>
</student>
</class_list>
~in other terms I should be able to have the output of
Code: [Select]
<class_list>
<Motley>
<name>Robert</name>
<grade>A+</grade>
</Motley>
<Kiki>
<name>Jessica</name>
<grade>A-</grade>
</Kiki>
<spYder>
<name>Lenard</name>
<grade>B+</grade>
</spYder>
<Kewun>
<name>Sebastian</name>
<grade>F-</grade>
</Kewun>
</class_list>

I promise if the source for xml is updated I will create a tutorial for xml accounting Here: Clicky Under Xml, Hopefully developers will release the red link functions for xml so I can figure out the LU output of Xml.

Until then topic locked to prevent spamerbots, " :P Feel free to PM me if you have any input you would like to add and I will unlock".
« Last Edit: August 22, 2016, 11:58:55 pm by Mötley »

SugarD

  • Asshat Gaming Founder
  • Tester
  • Sr. Member
  • ****
  • Posts: 820
  • Karma: +37/-75
  • STOP IN THE NAME OF THE COLESLAW!
    • View Profile
    • Clan Xperience
Re: XML help
« Reply #5 on: September 16, 2016, 06:10:38 pm »
Just for reference, "redlinks" on the Wiki aren't broken links. It means the page being referenced doesn't exist yet. Someone hasn't written up anything for that particular page for it to be created.

 

© Liberty Unleashed Team.