Minor file:write issue...

Discuss, ask for help, share ideas, give suggestions, read tutorials, and tell us about bugs you have found with MicroMacro in here.

Do not post RoM-Bot stuff here. There is a subforum for that.
Forum rules
This is a sub-forum for things specific to MicroMacro.

This is not the place to ask questions about the RoM bot, which uses MicroMacro. There is a difference.
Post Reply
Message
Author
Exempt
Posts: 197
Joined: Wed Jan 20, 2010 9:55 am

Minor file:write issue...

#1 Post by Exempt » Sun Mar 14, 2010 9:21 pm

I made a script that creates my paths for me but i'm having a problem...

The out put of my script is...

Code: Select all

desX = { 289,298,1,301,309,1, };
desY = { 322,317,1,320,320,1, };
What it should do it take away the last "," on desX and desY...

This is what i use to right to my file...

Code: Select all

file:write("desX = { ");
		file:write(listX);
		file:write("\b };\ndesY = { ");
		file:write(listY);
		file:write("\b };");
Erm, I just had a thought.. Maybe i should turn the entire desX and desY into one string then pass it through file:write one time... Maybe that would allow /b to work correctly?

Edit: Awe, I thought i might be wrong... I was just hoping it was a problem with file:write and not\b...

I changed my code to this and have nothing good to report...

Code: Select all

tmpString = "desX = { " .. listX .. "\b };\n" .. "desY = { " .. listY .. "\b };"
		file:write(tmpString);

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: Minor file:write issue...

#2 Post by Administrator » Mon Mar 15, 2010 6:48 am

Why are you using the \b?

Why don't you just do this:

Code: Select all

file:write("desX = {");
for i = 1,#desX-2
  -- for each desX (except last two), add: index, 
  file:write(string.format("%d, ", desX[i]));
end
-- for the last entry we want to print out: index};
file:write(string.format("%d};", desX[#desX-1]));

Exempt
Posts: 197
Joined: Wed Jan 20, 2010 9:55 am

Re: Minor file:write issue...

#3 Post by Exempt » Mon Mar 15, 2010 11:11 am

Cause \b said it would put a back space in...seemed easy.

Edit: listX and listY are strings. It won't let me use the for loop like that.

Edit: Is there a function could use that would just delete a character in my string at position x?

Edit: I couldn't find a function for deleting a character in my string but maybe there is a function to take away the last character in a string?

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: Minor file:write issue...

#4 Post by Administrator » Mon Mar 15, 2010 12:12 pm

Code: Select all

local newStr = string.sub(oldStr, 1, #oldStr-2); -- this would make newStr the same as oldStr except for the last 2 characters.

Exempt
Posts: 197
Joined: Wed Jan 20, 2010 9:55 am

Re: Minor file:write issue...

#5 Post by Exempt » Mon Mar 15, 2010 5:50 pm

I'll give that a try thanks.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest