Author Topic: LoadArray  (Read 13729 times)

pncdaspropagandas

  • Contributor
  • Active Member
  • *****
  • Posts: 93
    • View Profile
LoadArray
« on: January 27, 2017, 16:47:06 »
Hi,

I'm implementing a scrap area that I can Add/Remove files to it.

When I execute the command:
@var $temp_scrap_file = ".\Config\Scrap\scrap.txt";
$old_items = LoadArray($temp_scrap_file);
if the txt file is empty MC immediately closes

I will do a verification if the file is empty prior to LoadArray, but I would like just to let you guys now

Thanks

AlanJB

  • VIP Member
  • *****
  • Posts: 436
  • VERY old Programmer
    • View Profile
Re: LoadArray
« Reply #1 on: January 27, 2017, 17:33:28 »
Try:

@var $temp_scrap_file = ".\\Config\\Scrap\\scrap.txt";
@var $old_items[] = LoadArray($temp_scrap_file);
« Last Edit: January 27, 2017, 17:42:51 by AlanJB »

pncdaspropagandas

  • Contributor
  • Active Member
  • *****
  • Posts: 93
    • View Profile
Re: LoadArray
« Reply #2 on: January 27, 2017, 17:45:31 »
you killed it  :)

sorry, i'm not used to declare @var

AlanJB

  • VIP Member
  • *****
  • Posts: 436
  • VERY old Programmer
    • View Profile
Re: LoadArray
« Reply #3 on: January 28, 2017, 00:25:37 »
Did it work OK?

Quote
sorry, i'm not used to declare @var

Me either - I used a language that didn't use scripting at all , but it all makes sense! Trust Mathias ;)

(BTW Jungle is the scripting guru here [certainly not me] - he'll always put you right)

MC is a damned good tool; learn the syntax (and take a little time to learn the difference between MultiScript & Custom Commands) and it all hangs together :)

pncdaspropagandas

  • Contributor
  • Active Member
  • *****
  • Posts: 93
    • View Profile
Re: LoadArray
« Reply #4 on: January 29, 2017, 03:52:26 »
I'm not sure if it did work or not because I found out after that there are more factors involved. I was saving the scrap file as Unicode  UTF8 (SaveArray). If the array is empty, the created file uses BOM I think, and that writes some bytes at the file although the Notepad++ interface doesn't show nothing. You can see those bytes using a Hex Editor (I use a Notepad++ addon)

After all I implemented an empty file check to avoid loading an empty file and used ANSI to write the file and avoid the BOM bytes.

Yes, I'm loving MC and I did a Notepad++ User Defined Language to support MC Script. I'm posting it on User Contributed Content.