View unanswered posts | View active topics It is currently Sun Apr 19, 2026 5:21 am



Reply to topic  [ 8 posts ] 
 cuttext question. 
Author Message
Veteran Op
User avatar

Joined: Sat Dec 29, 2007 5:06 pm
Posts: 2059
Location: Oklahoma
Unread post cuttext question.
I randomly have problems using this command, I have an example of one method that works and one that doesn't. The idea was I am cutting about 130 lines and I was using the "=" to find the leading position and I wanted all text after it. But if I use the "add $pos 1" it fails on the 4th or 5th since this is gathering data for all games. It produces a can't cuttext past the end of line...blah blah blah
Maybe I am missing something but why? I have tried short & long delays thinking it might not be done doing something before starting the next round... Does anyone else have the same issue, it is not the first time I have had a problem with this command I can't seem to wrap my mind around why adding a "add $pos 1" would cause it to crash the script.

This randomly fails....
Code:
while ($kk < $i)
   getwordpos $stats[$kk] $pos "="
   add $pos 1
   cuttext $stats[$kk] $var[$mm] $pos 30
   add $mm 1
   add $kk 1
end


This works......
Code:
while ($kk < $i)
   getwordpos $stats[$kk] $pos "="
   cuttext $stats[$kk] $var[$mm] $pos 30
   replacetext $var[$mm] "=" " "
   add $mm 1
   add $kk 1
end

_________________
T0yman (Permanently Retired since 2012)
Proverbs 17:28 <-- Don't know it, most should it would stop a lot of the discussions on here.


Thu Mar 29, 2012 12:15 pm
Profile ICQ YIM WWW
Ensign

Joined: Wed Nov 06, 2002 3:00 am
Posts: 270
Unread post Re: cuttext question.
Toyman, this is just a guess on my part, as I've been away from the game and scripting for some time, but here goes my guess.

My understanding of the situation is that your line from the game or text file is always the same length after the "="?

I am thinking that what is happening in the first block of code is that if the text block you want is 30 characters long as you start with it, perhaps by adding 1 to $pos it is cutting the length of the text block to 29 characters and the 30 would put it past the end of the text block you want, out past the 'end of line'.

If the line is coming from a text file, check to see if there is a space at the end of some of the lines and not at the end of the others. If so, then the space might be allowing it to function for a few lines but when it runs into a line without a space at the end then 30 would put you out past 'end of line'.

If it is lines coming from the game in real time then I can't really account for why it would be doing this.

Like I said, I'm pretty rusty with the scripting, so I may not know what I'm talking about here and maybe I'm on the wrong track. Hopefully someone else will know the answer if my guess is incorrect.

Edit
Actually, if I am on the right track, adding 1 to $pos might be taking you further into the block of text, as the getWordPos command uses a count of the words if I remember correctly. So adding 1 to $pos would actually take you to the next word in the text block.


Thu Mar 29, 2012 12:53 pm
Profile
Veteran Op
User avatar

Joined: Sat Dec 29, 2007 5:06 pm
Posts: 2059
Location: Oklahoma
Unread post Re: cuttext question.
Example of lines I am grabbing. The line length could be upto 60 max but I am only wanting 30 since the rest would be prior to the = .

Local Game Time=03/29/40 01:31:32 PM
Active Players=0
Percent Players Good=N/A
Active Aliens=0
Percent Aliens Good=N/A


First thing I am doing is grabbing the entire line using

setvar $line[$idx] CURRENTLINE
then I remove the "Local Game Time" and keep "=03/29/40 01:31:32 PM"

This is all being done using array's so it's not actually real time, I can grab the data with the = but if I add 1 to remove it fails...but not consistant.
I don't mind a challenge so doing a new work around it fine, just wondering if others have had the same issue and it they know why :)

_________________
T0yman (Permanently Retired since 2012)
Proverbs 17:28 <-- Don't know it, most should it would stop a lot of the discussions on here.


Thu Mar 29, 2012 1:26 pm
Profile ICQ YIM WWW
Ensign

Joined: Wed Nov 06, 2002 3:00 am
Posts: 270
Unread post Re: cuttext question.
T0yman wrote:
Local Game Time=03/29/40 01:31:32 PM
Active Players=0
Percent Players Good=N/A
Active Aliens=0
Percent Aliens Good=N/A


I see what you're talking about Toyman. :D I think it is working better with that replaceText line because =03/29/40 would all be treated as one word. If you are wanting to get text from = to the end of the line every time, SupG and some of the other scripters helped me work out a way to do that fairly easy. Was something like this :
Code:
setVar $line $line & "EOL"
getText $line $var "=" "EOL"


I was asking for EOL to be hard coded or whatever into TWX and Xide might have done that in one of the versions after 2.0 because he said in that discussion that this was actually something he had been wanting too.

And if I remember correctly (it was back in 03 and I'm not getting any younger :lol: ) I think I was able to use just EOL in some of my scripts after that, without having to merge text with that setVar line adding "EOL" or "[EOL]" or whatever you wanted to use to the end of the original line, like after 2.0 or 2.01 came out or something. I will have to play with it in a simple script and see if that works.

The discussion was over at http://www.twxproxy.com/support.php?show=538&start=136

I was Thor over there. Just another way to think about doing it. :D


Thu Mar 29, 2012 2:32 pm
Profile
Gameop
User avatar

Joined: Tue Nov 19, 2002 3:00 am
Posts: 1050
Location: USA
Unread post Re: cuttext question.
Curiousity speaking for me here. Whats the error being thrown at you from twx?

_________________
Dark Dominion TWGS
Telnet://twgs.darkworlds.org:23
ICQ#31380757, -=English 101 pwns me=-
"This one claims to have been playing since 1993 and didn't know upgrading a port would raise his alignment."


Thu Mar 29, 2012 3:40 pm
Profile ICQ
Veteran Op
User avatar

Joined: Sat Dec 29, 2007 5:06 pm
Posts: 2059
Location: Oklahoma
Unread post Re: cuttext question.
SteveH_66 wrote:
I was Thor over there. Just another way to think about doing it. :D

Never used the "EOL" before, thanks I will give that article a read.

Kaus there was no error, script would just crash saying it can't read past the end of the line. It just wasn't consistent....sometimes it worked sometimes it didn't :)

_________________
T0yman (Permanently Retired since 2012)
Proverbs 17:28 <-- Don't know it, most should it would stop a lot of the discussions on here.


Thu Mar 29, 2012 4:50 pm
Profile ICQ YIM WWW
Ambassador
User avatar

Joined: Mon Feb 09, 2004 3:00 am
Posts: 3141
Location: Kansas
Unread post Re: cuttext question.
T0yman wrote:
SteveH_66 wrote:
I was Thor over there. Just another way to think about doing it. :D

Never used the "EOL" before, thanks I will give that article a read.

Kaus there was no error, script would just crash saying it can't read past the end of the line. It just wasn't consistent....sometimes it worked sometimes it didn't :)


You can probably do it a couple of ways:

cutText $someText $toText $pos 999

or

use a getlength for the var/text to cut from and subtract pos to get the ending length.

I've never used EOL

_________________
               / Promethius / Enigma / Wolfen /

"A man who has no skills can be taught, a man who has no honor has nothing."


Thu Mar 29, 2012 5:40 pm
Profile ICQ
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post Re: cuttext question.
Code:
  if (V1 > Length(Params[0].Value)) then
    raise EScriptError.Create('CutText: Cannot cut from past end of text');

This is the code from the cutText command. Params[0].Value is the text that you are manipulating. V1 is the starting location. If you are getting that error, it's because your starting point is > the length of the text you're manipulating.

The error should be more like 'CutText: Start position ($value) is greater than the line's length ($length).'

You could test this yourself to determine if its TWX or your code.
Code:
while ($kk < $i)
   getwordpos $stats[$kk] $pos "="
   add $pos 1
   getLength $stats[$kk] $length
   if ($pos > $length)
      echo "*Error, $pos (" & $pos & ") > $length (" & $length & ")."
      pause
   end
   cuttext $stats[$kk] $var[$mm] $pos 30
   add $mm 1
   add $kk 1
end

My guess - you're doing this in a while loop, against an array, and one of the array values is blank.

+EP+

_________________
Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.


Thu Mar 29, 2012 7:45 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 8 posts ] 

Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by wSTSoftware.