|
Page 1 of 1
|
[ 10 posts ] |
|
| Author |
Message |
|
Zoso
Ensign
Joined: Fri Sep 19, 2003 2:00 am Posts: 247 Location: Canada
|
Here is a piece of code im writing;
Set Array $XXXX SECTORS
:Loopy
Read $DEFilename $Sector $Line
While ($Sector <> EOF)
GetCourse $Course $SD $Sector
While ($i <= $Course)
SetVar $XXXX($Course[$i]) 3
Add $i
Goto :Loopy
I am having some diffuculty understanding the array function. If i have dimensioned my array to = SECTORS (5000 in this case) how do i go about setting a value for $i of 5000? where $i is expectant of a sector number (ie; $i = 220)
Any help would be appreciated.
Zozo.
_________________ No Quarter - Is what we offer our enemies
|
| Thu Feb 03, 2005 3:38 pm |
|
 |
|
Psion
Ensign
Joined: Tue Jan 11, 2005 3:00 am Posts: 297 Location: USA
|
Hmm, where to start... Well first off, you're gonna have lots of little compiler errors with this code. Like, the two WHILE statements don't have an ENDs, EOF must be in quotes - like this: "EOF", and SetArray is all one word, etc. But what I think you are confused on is how to work with array indexes. You are creating a static array of SECTORS entries, to get at the info stored in each 'slot', you need to use an index. So ARRAY[1] would give you whatever is in slot 1, ARRAY[2] would give you whatever is in slot 2, etc. Of course this is usually done with a variable instead of a hardcoded number (for obvious reasons). Array values can be stored with a simple "setVar Array[x] 2" kind of statement.
I must admit to being slightly confused as to what you are trying to accomplish with this code though... If you could explain what it you're wanting to do, I'd be happy to help with it.
_________________ --==[The Outfit]==--
Member of The Foundation
Hereby it is manifest, that during the time men live without a common power to keep them all in awe, they are in that condition which is called war; and such a war, as is of every man, against every man. For WAR, consisteth not in battle only, or the act of fighting; but in a tract of time, wherein the will to contend by battle is sufficiently known.
--Hobbes, Leviathan
|
| Thu Feb 03, 2005 4:04 pm |
|
 |
|
Zoso
Ensign
Joined: Fri Sep 19, 2003 2:00 am Posts: 247 Location: Canada
|
Well, like i said its only a piece of the code and not a very good selection at that now that i look at it. But no worries about the WHILES they and all of my IF statements are closed properly and my script complies fine without enclosing EOF in double quotes (You would normally do this for a variable that is a string, same for a variable that is an interger, "WORD" or '4'.Please correct me if im wrong.Somewhat new to this language.)
IF i understand you correctly Psion, IF my statement goes like this
SetVar ARRAY[$i] 3 (ARRAY being my array and [$i] being the sector number passed) then for argument sake ARRAY[2] would be equal to 3.
Where im having problems (and the part I didn't post) is when i try to enumerate my index by 3, i get some funky results.
SetVar ARRAY[$i] ARRAY[$i] 3 <- No Workie [V]
Zozo
_________________ No Quarter - Is what we offer our enemies
|
| Thu Feb 03, 2005 4:54 pm |
|
 |
|
Zoso
Ensign
Joined: Fri Sep 19, 2003 2:00 am Posts: 247 Location: Canada
|
quote:IF i understand you correctly Psion, IF my statement goes like this
ROFL, Too many IF,THEN,ELSE Statments.
_________________ No Quarter - Is what we offer our enemies
|
| Thu Feb 03, 2005 5:00 pm |
|
 |
|
Psion
Ensign
Joined: Tue Jan 11, 2005 3:00 am Posts: 297 Location: USA
|
quote:my script complies fine without enclosing EOF in double quotes
Really? Mine gave me grief without the quotes. *shrug*
quote:IF i understand you correctly Psion, IF my statement goes like this SetVar ARRAY[$i] 3 (ARRAY being my array and [$i] being the sector number passed) then for argument sake ARRAY[2] would be equal to 3.
Assuming $i = 2, then yes, thats correct.
quote:SetVar ARRAY[$i] ARRAY[$i] 3 <- No Workie
Well the problem with this statement is that you have too many arguments. What exactly do you mean by enumerate your index by 3?
If you want to increase your index by 3, all you have to do is Add $i 3. So, for example:
###Adds the numbers 1 through 50 to a static array
#Sets the index variable (also used as a loop counter)
setVar $i 1
#Creates a static array with a size of 50
setArray $array 50
#Loop to do all the grunt work, and stop the script at 50
While ($i <= 50)
#Stores the value of the integer $i into the array at index $i
setVar $array[$i] $i
#Increments $i
add $i 1
END
So this script would store the number 1 into array[1], the number 2 into array[2], etc. Hope this helps, keep posting if it doesn't. I'm a programmer with too much free time  You can also ICQ me at 211279673 if you prefer.
_________________ --==[The Outfit]==--
Member of The Foundation
Hereby it is manifest, that during the time men live without a common power to keep them all in awe, they are in that condition which is called war; and such a war, as is of every man, against every man. For WAR, consisteth not in battle only, or the act of fighting; but in a tract of time, wherein the will to contend by battle is sufficiently known.
--Hobbes, Leviathan
|
| Thu Feb 03, 2005 5:53 pm |
|
 |
|
Zoso
Ensign
Joined: Fri Sep 19, 2003 2:00 am Posts: 247 Location: Canada
|
Ill hit you up on ICQ after work (system locked down here for PM's)
_________________ No Quarter - Is what we offer our enemies
|
| Thu Feb 03, 2005 5:59 pm |
|
 |
|
Zoso
Ensign
Joined: Fri Sep 19, 2003 2:00 am Posts: 247 Location: Canada
|
Ok, after much trial and error, I seem to have corrected the problem.
Read $DEFilename $Sector $Line
While ($Sector <> "EOF")
GetCourse $Course $SD $Sector
While ($i <= $Course + 1)
SetVar $Index $Course[$i]
SetVar $ARRAY[$Index] 3
Add $i 1
END
Add $Line 1
Goto :Loopy
END
For some reason I had to ReDim the index and use a second variable ( I was hoping i could use $i as not only a counter but also the Sector number)
SetVar $Index $Course[$i]
Thanx for the help Psion, and ill probably take you up on your offer in the future.
BTW I added the "EOF", however it seems to work both ways?
_________________ No Quarter - Is what we offer our enemies
|
| Thu Feb 03, 2005 6:58 pm |
|
 |
|
Psion
Ensign
Joined: Tue Jan 11, 2005 3:00 am Posts: 297 Location: USA
|
quote:Read $DEFilename $Sector $Line
While ($Sector <> "EOF")
GetCourse $Course $SD $Sector
While ($i <= $Course + 1)
SetVar $Index $Course[$i]
SetVar $ARRAY[$Index] 3
Add $i 1
END
Add $Line 1
Goto :Loopy
END
OK, here's how you can do it without $Index:
setVar $ARRAY[$Course[$i]] 3
Snazzy, huh? Also, unless you are resetting $i back to 0 (or 1, depending on how and where you increment) somewhere else in the code, you will pry run into problems. You would need to reset $i after each warp course is fully plotted. As is, $i will keep increasing until it is always past $Course. The program will still run without compiler errors, but it will stop returning useful info pretty quickly.
_________________ --==[The Outfit]==--
Member of The Foundation
Hereby it is manifest, that during the time men live without a common power to keep them all in awe, they are in that condition which is called war; and such a war, as is of every man, against every man. For WAR, consisteth not in battle only, or the act of fighting; but in a tract of time, wherein the will to contend by battle is sufficiently known.
--Hobbes, Leviathan
|
| Thu Feb 03, 2005 7:16 pm |
|
 |
|
Zoso
Ensign
Joined: Fri Sep 19, 2003 2:00 am Posts: 247 Location: Canada
|
Hmmm, I Though that is how i orignally had the code, but have since gotten it working and saved over the orignal bit.
Nods on the $i, i reset under my sub :Loopy. Now trying to increment the value of ARRAY[$Index] by itself plus 3 more
_________________ No Quarter - Is what we offer our enemies
|
| Thu Feb 03, 2005 7:31 pm |
|
 |
|
Psion
Ensign
Joined: Tue Jan 11, 2005 3:00 am Posts: 297 Location: USA
|
quote:Now trying to increment the value of ARRAY[$Index] by itself plus 3 more
Simple:
Add ARRAY[$Index] 3
_________________ --==[The Outfit]==--
Member of The Foundation
Hereby it is manifest, that during the time men live without a common power to keep them all in awe, they are in that condition which is called war; and such a war, as is of every man, against every man. For WAR, consisteth not in battle only, or the act of fighting; but in a tract of time, wherein the will to contend by battle is sufficiently known.
--Hobbes, Leviathan
|
| Thu Feb 03, 2005 7:33 pm |
|
 |
|
|
Page 1 of 1
|
[ 10 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 12 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
|
|