View unanswered posts | View active topics It is currently Thu Apr 23, 2026 12:29 am



Reply to topic  [ 10 posts ] 
 array size 
Author Message
Ensign
User avatar

Joined: Tue Jul 21, 2009 2:37 pm
Posts: 241
Location: Ottawa, Canada
Unread post array size
Having problems with a script... after pulling my hair a little, turns out that my array size is zero. So I write a little test script:

Code:
#test.ts
setArray $fig_output 8
echo "** fig_output array size: "& $fig_output & "**"


output:
--------------------------------------------------------------
Loading and compiling script: scripts\testfig.ts

Command [TL=00:00:00]:[77] (?=Help)? :

fig_output array size: 0

Script terminated: scripts\testfig.ts
--------------------------------------------------------------

Wtf????


Last edited by Hotblack Desiato on Fri Oct 02, 2009 2:32 pm, edited 1 time in total.



Fri Oct 02, 2009 12:38 pm
Profile
Ensign
User avatar

Joined: Tue Jul 21, 2009 2:37 pm
Posts: 241
Location: Ottawa, Canada
Unread post Re: array vars
Okay... seriously....

Code:
#testArraySize.ts
setArray $figArray 2
setVar $figArray[1] "one"
setVar $figArray[2] "two"
echo "*" $figArray[1] "*"
echo "*" $figArray[2] "*"
echo "** figArray size: " $figArray "**"
halt


------------------ output ---------------------------------------
Loading and compiling script: scripts\testArraySize.ts

Citadel command (?=help)
one

two


figArray size: 0


Script terminated: scripts\testArraySize.ts
------------------ /output ---------------------------------------


Fri Oct 02, 2009 1:49 pm
Profile
Ensign
User avatar

Joined: Tue Jul 21, 2009 2:37 pm
Posts: 241
Location: Ottawa, Canada
Unread post Re: array size
Help!!


Fri Oct 02, 2009 2:33 pm
Profile
Lieutenant J.G.
User avatar

Joined: Sun Mar 13, 2005 3:00 am
Posts: 387
Location: USA
Unread post Re: array size
From looking over the old source code I can't see anywhere EP sets the arrayname = count of array except in his new routines
I.E. and I have noticed that the documentation is incorrect

in the documentation of GetCourse

From Example of GetCourse

getCourse $course 1 10

Would return:

$course = 2
$course[1] = 1
$course[2] = 2
$course[3] = 10

The variable course is an array with length 3 so $course should be set to 3 instead it is set to 2

I have found it in the source code and the documentation is correct

Around line 384 in function GetCourse in file ScriptCmd.pas
try
Params[0].Value := IntToStr(Course.Count - 1);

This is documented from Xide I believe but Elder has fixed some but not all
Array==LengthOfArray

Nice catch of that bug.... Undocumented Feature I mean
Heh it's the old One off error.... arrays in most languages start at 0 while most humans use 1


There are no bugs in TWXProxy :)

_________________
Find out just what any people will quietly submit to and you have the exact measure of the injustice and wrong which will be imposed on them. Frederick Douglas


Fri Oct 02, 2009 4:26 pm
Profile ICQ
Ensign
User avatar

Joined: Tue Jul 21, 2009 2:37 pm
Posts: 241
Location: Ottawa, Canada
Unread post Re: array size
Thanks Maniac, this is driving me nuts...

but I'm not following... how do i fix it? It's not just one-off for me, it's giving array size 0 no matter what.

I don't get it... I'm sure I've used array size before and it's worked fine.


Fri Oct 02, 2009 4:42 pm
Profile
Lieutenant J.G.
User avatar

Joined: Sun Mar 13, 2005 3:00 am
Posts: 387
Location: USA
Unread post Re: array size
From more investigating is is only on Static arrays that don't get the Array[0]=SizeofArray
I looked at GetNearestWarps,FileList,and a couple of other routines that
return Arrays and I see that they work as advertised.


There are a couple more areas I am unsure of such as GetCourse tries to return the # of steps from a to b
but forgets you have one extra step in there

GetCourse 1 10 will return 2 when there are 3 elements i.3. 1.2.10
I think this is because we also use GetDistance which is 2... 1->2 is 1 and 2->10 is 2 so the distance between 1-10 is 2 hops


Maybe EP will chime in on this and let us know.

_________________
Find out just what any people will quietly submit to and you have the exact measure of the injustice and wrong which will be imposed on them. Frederick Douglas


Fri Oct 02, 2009 5:39 pm
Profile ICQ
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post Re: array size
Not that you need it, when you use setArray you have to know the size somewhere anyway... ;)

It used to never report the size, that was a problem for internal algos that generated arrays since you'd have to count them. EP
added the convention where $var = sizeof($var[]) for returned arrays. But since $var and $var[] are 2 different entities, it's only
true of places where $var[] is populated internally by a twxproxy command. It would be nice to have a sizeof() command tho.

This isn't really a bug. And it shouldn't be changed, it'll break scripts if you do. Some of us are used to $var and $var[] being
completely separate, and we use them as such. If you need $var to report sizeof($var[]) in your script then init it at the top and
just "add $var 1" along the way.

IMO, $var should not automatically report sizeof($var[]) for every single array. It would be useful tho to have a SizeOf or ArraySize
command for times where it's needed.

_________________
May the unholy fires of corbomite ignite deep within the depths of your soul...

1. TWGS server @ twgs.navhaz.com
2. The NavHaz Junction - Tradewars 2002 Scripts, Resources and Downloads
3. Open IRC chat @ irc.freenode.net:6667 #twchan
4. Parrothead wrote: Jesus wouldn't Subspace Crawl.

*** SG memorial donations via paypal to: dpocky68@booinc.com
Image


Fri Oct 02, 2009 6:31 pm
Profile ICQ WWW
Ensign
User avatar

Joined: Tue Jul 21, 2009 2:37 pm
Posts: 241
Location: Ottawa, Canada
Unread post Re: array size
Thanks for explaining that. Weird. I agree there should just be a sizeof command or operator (or whatever people want to call it).

Quote:
Not that you need it, when you use setArray you have to know the size somewhere anyway... ;)


Strange, but I hadn't thought of that. I guess oop has brainwashed me over the years - the object should know how big it is, but of course this isn't oop.


Fri Oct 02, 2009 6:35 pm
Profile
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post Re: array size
hehe. Yeh, from an OOP perspective it's all weird. OOP makes a lot of assumptions.

_________________
May the unholy fires of corbomite ignite deep within the depths of your soul...

1. TWGS server @ twgs.navhaz.com
2. The NavHaz Junction - Tradewars 2002 Scripts, Resources and Downloads
3. Open IRC chat @ irc.freenode.net:6667 #twchan
4. Parrothead wrote: Jesus wouldn't Subspace Crawl.

*** SG memorial donations via paypal to: dpocky68@booinc.com
Image


Fri Oct 02, 2009 7:13 pm
Profile ICQ WWW
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post Re: array size
All of the behavior mentioned is intentional. All of the commands that create a size variable with the same name as the array (getAllCourses, getCourse, getNearestWarps, listActiveScripts, listAvoids, listSectorParameters, readToArray) document this functionality, all added by me except getCourse, and all actually specify the size except for the 2 course commands. The behavior of the getCourse command was logical to Xide, and it made sense for me to mimic this established behavior with the getAllCourses command.

Despite the above commands, TWX does not track the size of arrays in a way that is available to a script, nor is there any general function to determine the size of an array. And I agree that it is sorely needed.

I wrote about some of this in an earlier thread, which may clarify some of it for you: http://www.classictw.com/viewtopic.php?p=189560#p189560

And if I can clarify further, let me know.

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


Fri Oct 02, 2009 9:46 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 10 posts ] 

Who is online

Users browsing this forum: No registered users and 21 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.