Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
Hello fellow Cemetechians!

I've been trying to update The Oregon Trail CE from ICE 1.0 to ICE 2.0, but am running into some problems. I'm currently working on a new saving system for the game, but can't seem to figure out how ICE's File/Memory functions work

This is what I've got so far:



Code:

[i]Loading
CloseAll
If not(Open("OREFILE","r+"
   Open("OREFILE","w+"->XZ
   Data(6,0,0,0,0,0,0,0,0,0,0,0,0,0,0)->DATA
   Write(DATA,84,1,XZ
   End
   Read(DATA,84,1,XZ
Copy(L5,DATA,14
L5(1)->OXEN
L5(2)->FOOD
L5(3)->AMMO
L5(4)->PARTS
L5(5)->PACE
L5(6)->RATION
L5(7)->D
L5(8)->E
L5(9)->F
L5(10)->H
L5(11)->K
L5(12)->L
L5(13)->M
L5(14)->T

[i]Saving
OXEN->L5(1)
FOOD->L5(2)
AMMO->L5(3)
PARTS->L5(4)
PACE->L5(5)
RATION->L5(6)
D->L5(7)
E->L5(8)
F->L5(9)
H->L5(10)
K->L5(11)
L->L5(12)
M->L5(13)
T->L5(14)
CloseAll
If not(Open("OREFILE","r+
   Open("OREFILE","w+"->XZ
   Data(6,0,0,0,0,0,0,0,0,0,0,0,0,0,0->DATA
   Write(DATA,84,1,XZ
End
Copy(DATA,L5,14
Write(DATA,84,1,XZ
SetArchiveStatus(1,XZ
CloseAll


As you may notice, I'm trying to store L5 into an appvar called OREFILE. I've looked at snippets from other ICE programs and this is what I came up with, but it doesn't seem to work.

I don't really understand what Pointers, Size, Count, Slot, and Offset refers to in the commands. Any help is appreciated!
OldNewTimer wrote:
Hello fellow Cemetechians!

I've been trying to update The Oregon Trail CE from ICE 1.0 to ICE 2.0, but am running into some problems. I'm currently working on a new saving system for the game, but can't seem to figure out how ICE's File/Memory functions work

This is what I've got so far:



Code:

[i]Loading
CloseAll
If not(Open("OREFILE","r+"
   Open("OREFILE","w+"->XZ
   Data(6,0,0,0,0,0,0,0,0,0,0,0,0,0,0)->DATA
   Write(DATA,84,1,XZ
   End
   Read(DATA,84,1,XZ
Copy(L5,DATA,14
L5(1)->OXEN
L5(2)->FOOD
L5(3)->AMMO
L5(4)->PARTS
L5(5)->PACE
L5(6)->RATION
L5(7)->D
L5(8)->E
L5(9)->F
L5(10)->H
L5(11)->K
L5(12)->L
L5(13)->M
L5(14)->T

[i]Saving
OXEN->L5(1)
FOOD->L5(2)
AMMO->L5(3)
PARTS->L5(4)
PACE->L5(5)
RATION->L5(6)
D->L5(7)
E->L5(8)
F->L5(9)
H->L5(10)
K->L5(11)
L->L5(12)
M->L5(13)
T->L5(14)
CloseAll
If not(Open("OREFILE","r+
   Open("OREFILE","w+"->XZ
   Data(6,0,0,0,0,0,0,0,0,0,0,0,0,0,0->DATA
   Write(DATA,84,1,XZ
End
Copy(DATA,L5,14
Write(DATA,84,1,XZ
SetArchiveStatus(1,XZ
CloseAll


As you may notice, I'm trying to store L5 into an appvar called OREFILE. I've looked at snippets from other ICE programs and this is what I came up with, but it doesn't seem to work.

I don't really understand what Pointers, Size, Count, Slot, and Offset refers to in the commands. Any help is appreciated!


1: Opening a file more than once without closing it will likely cause some memory errors, so try this:

Code:

sum(1,FILE,"r→D
sum(6,D→C
sum(3,D
If C=-1
//your code for creating the file goes here, make sure to use 'sum(3'
End

2: I don't know how os lists work in ICE, but I can help you with pointers.
Pointers 'point' to a memory adress.
The byte stored at that adress is returned when you do this: *{PTR}
NOTE: this will return one byte, 0-255
In order to get more bytes, **{PTR} will get two, and {PTR} or ***{PTR} will get three.
So in order to get bytes in a list, take the pointer that was returned when you created it, and add the index. {PTR+I}.
NOTE: This will get the byte offset, so if you want a list that can contain numbers greater than 255, you will have to add more than 1 between indexes, like so:

Code:

{PTR+I→C
I+3→I

This would get three bytes from each index, so a number between 0 and 16777215, which is the highest possible number in ICE.
3: If you're trying to get a bunch of zeroes into a list, try using 'Alloc(BYTES' which is used for that Razz
4: 'write(DATA,LEN,COUNT,SLOT'
DATA is a pointer to a byte in memory, LEN is the amount of bytes (times COUNT) to read from DATA, and COUNT is the number of bytes per index, so 1,2 or 3.
5: 'Copy(DESTINATION,SOURCE,SIZE' will copy SIZE bytes from SOURCE to DESTINATION, but DESTINATION must be a pointer that has SIZE bytes allocated after and including itself.
6: 'read(PTR,LEN,COUNT,SLOT' copies LEN*COUNT bytes from SLOT to PTR. PTR must already have LEN*COUNT bytes allocated
7: you don't need to use L₁, there are a nearly infinite number of other variable names to choose from Razz
I see these problems with the code:
1) you're opening the appvar twice. Open it once and store the slot in a variable; after that you can check if the slot is nonzero.
2) What is DATA when Open("OREFILE","r+") returns 1-5? Then the condition is false and it skips the If statement.
If you want to understand pointers, look at the post above Razz
I'm still kind of confused about this stuff Confused
What I'm trying to do is copy all of the data in List 5 (It has about 20 different values in it) to an appvar.

beckadamtheinventor wrote:
The byte stored at that address is returned when you do this: *{PTR}
NOTE: this will return one byte, 0-255

So a pointer is a byte stored at a memory address?
Also, what do I put for "PTR"?

beckadamtheinventor wrote:
NOTE: This will get the byte offset, so if you want a list that can contain numbers greater than 255, you will have to add more than 1 between indexes, like so:

What is an offset?
Also, my list contains numbers that are less than 65536, so would I do

Code:
{PTR+I→C
I+2→I


beckadamtheinventor wrote:
4: 'write(DATA,LEN,COUNT,SLOT'
DATA is a pointer to a byte in memory, LEN is the amount of bytes (times COUNT) to read from DATA, and COUNT is the number of bytes per index, so 1,2 or 3.

What do I put for SLOT?


beckadamtheinventor wrote:
5: 'Copy(DESTINATION,SOURCE,SIZE' will copy SIZE bytes from SOURCE to DESTINATION, but DESTINATION must be a pointer that has SIZE bytes allocated after and including itself.


How would I allocate bytes for the pointer?



Anyways, thanks for all the help!
OldNewTimer wrote:
I'm still kind of confused about this stuff Confused
What I'm trying to do is copy all of the data in List 5 (It has about 20 different values in it) to an appvar.

beckadamtheinventor wrote:
The byte stored at that address is returned when you do this: *{PTR}
NOTE: this will return one byte, 0-255

So a pointer is a byte stored at a memory address?
Also, what do I put for "PTR"?

beckadamtheinventor wrote:
NOTE: This will get the byte offset, so if you want a list that can contain numbers greater than 255, you will have to add more than 1 between indexes, like so:

What is an offset?
Also, my list contains numbers that are less than 65536, so would I do

Code:
{PTR+I→C
I+2→I


beckadamtheinventor wrote:
4: 'write(DATA,LEN,COUNT,SLOT'
DATA is a pointer to a byte in memory, LEN is the amount of bytes (times COUNT) to read from DATA, and COUNT is the number of bytes per index, so 1,2 or 3.

What do I put for SLOT?


beckadamtheinventor wrote:
5: 'Copy(DESTINATION,SOURCE,SIZE' will copy SIZE bytes from SOURCE to DESTINATION, but DESTINATION must be a pointer that has SIZE bytes allocated after and including itself.


How would I allocate bytes for the pointer?



Anyways, thanks for all the help!


Yes, a pointer 'points' to memory.
PTR is the value that is stored into a variable when you define something.
Like so:

Code:

"Hello World→S
Alloc(64→PTR
Copy(PTR,S,length(S

An offset is like a list index, but added to a pointer, and the indexes are each one byte. You can access up to three bytes from this, using asterisks equal to the number of bytes you want to access.

Code:

Alloc(64→LIST
100→*{LIST
100000→{LIST+1
2→*{LIST+4
*{LIST→N

This would store 100 to the first byte at the adress LIST, then store 100000 to the three bytes at the adress LIST+1. The lack of asterisks before "{" will access three bytes. One asterisk acesses one byte, and two will access two.
Next it stores 2 to the adress LIST+4. Notice that I added 4 instead of 2? That's because data in ICE is stored by the byte, so a three byte number takes up three indexes.

SLOT is the number returned by "sum(1" (open) or "sum(2" (openVar). Note that you should not do any operations on the variable that you store the slot to, until you do "sum(3" (close), at which point the slot is no longer required to access that file.

Code:

sum(1,"FILENAME","r→D
//read from the file here
sum(3,D


To allocate bytes:

Code:

Alloc(BYTES→PTR


NOTE: I wouldn't reccomend that you be using the os lists with ICE, unles you absolutely have to. Idk how to do that correctly, so ask PT about it.
To use data instead of a list, there is a number of ways to acheive this:
:initialize variable with null (zeroes)

Code:

Alloc(BYTES→PTR

:initialize variable with data ("Data(" method)

Code:

Data(1,1,2,3,4,5→PTR
//first number is the number of bytes for each of the rest of the numbers

:initialize variable with data (string method)

Code:

"020406080A0C0E10→PTR
//data must be in hexadecimal (base 16 0-9,A-F)


Hope all this helps! Smile
Thanks for all of the help!

With the tips you gave and a few looks at other ICE programs, I was able to piece together this:

Code:

[i]Loading
If Y=90
CloseAll
   Alloc(28)->DATA
   Open("OREFILE","r"->ZZ
   Read(DATA,28,2,ZZ)
   SetArchiveStatus(1,ZZ)
   CloseAll
   If ZZ=0
      Goto MAIN
   End
   Copy(L5,DATA,28
   CloseAll
   L5(1)->OXEN
   L5(2)->FOOD
   L5(3)->AMMO
   L5(4)->PARTS
   L5(5)->PACE
   L5(6)->RATION
   L5(7)->D
   L5(8)->E
   L5(9)->F
   L5(10)->H
   L5(11)->K
   L5(12)->L
   L5(13)->M
   L5(14)->T
   Goto SIZE
End

[i]Saving
Lbl SAVE
   CloseAll
   Alloc(28)->DATA
   OXEN->L5(1)
   FOOD->L5(2)
   AMMO->L5(3)
   PARTS->L5(4)
   PACE->L5(5)
   RATION->L5(6)
   D->L5(7)
   E->L5(8)
   F->L5(9)
   H->L5(10)
   K->L5(11)
   L->L5(12)
   M->L5(13)
   T->L5(14)
   Copy(DATA,L5,28
   CloseAll
   Open("OREFILE","w"->ZZ
   Write(DATA,28,2,ZZ
   SetArchiveStatus(1,ZZ)
   Close(ZZ
Return


I'm still having a few problems though. Some values will load correctly, such as the OXEN variable. But others will display weird symbols or even letters, such as q792 food. Are there any problems in my code that might cause this? Thanks again for all of the help Smile
OldNewTimer wrote:
Thanks for all of the help!

With the tips you gave and a few looks at other ICE programs, I was able to piece together this:

Code:

[i]Loading
If Y=90
CloseAll
   Alloc(28)->DATA
   Open("OREFILE","r"->ZZ
   Read(DATA,28,2,ZZ)
   SetArchiveStatus(1,ZZ)
   CloseAll
   If ZZ=0
      Goto MAIN
   End
   Copy(L5,DATA,28
   CloseAll
   L5(1)->OXEN
   L5(2)->FOOD
   L5(3)->AMMO
   L5(4)->PARTS
   L5(5)->PACE
   L5(6)->RATION
   L5(7)->D
   L5(8)->E
   L5(9)->F
   L5(10)->H
   L5(11)->K
   L5(12)->L
   L5(13)->M
   L5(14)->T
   Goto SIZE
End

[i]Saving
Lbl SAVE
   CloseAll
   Alloc(28)->DATA
   OXEN->L5(1)
   FOOD->L5(2)
   AMMO->L5(3)
   PARTS->L5(4)
   PACE->L5(5)
   RATION->L5(6)
   D->L5(7)
   E->L5(8)
   F->L5(9)
   H->L5(10)
   K->L5(11)
   L->L5(12)
   M->L5(13)
   T->L5(14)
   Copy(DATA,L5,28
   CloseAll
   Open("OREFILE","w"->ZZ
   Write(DATA,28,2,ZZ
   SetArchiveStatus(1,ZZ)
   Close(ZZ
Return


I'm still having a few problems though. Some values will load correctly, such as the OXEN variable. But others will display weird symbols or even letters, such as q792 food. Are there any problems in my code that might cause this? Thanks again for all of the help Smile


non-number characters appearing before a number in ICE is what happens when you attempt to display a number using "det(15,N,Chars" but the number of digits to display (Chars) is less than the digits of the number.
Also: I highly reccomend that you don't use the os lists in ICE. Using ICE variables is better than using os lists, due to the os lists not working properly in ICE. This is likely causing the problem with "det(15".


Code:

[i]Loading
If Y=90
CloseAll
   Alloc(28)->DATA
   Open("OREFILE","r"->ZZ
   Read(DATA,28,1,ZZ)
   CloseAll
   If ZZ=0
      Goto MAIN
   End
   CloseAll
   **{DATA->OXEN
   **{DATA+2->FOOD
   **{DATA+4->AMMO
   **{DATA+6->PARTS
   **{DATA+8->PACE
   **{DATA+10->RATION
   **{DATA+12->D
   **{DATA+14->E
   **{DATA+16->F
   **{DATA+18->H
   **{DATA+20->K
   **{DATA+22->L
   **{DATA+24->M
   **{DATA+26->T
   Goto SIZE
End

[i]Saving
Lbl SAVE
   CloseAll
   Alloc(28)->DATA
   OXEN->**{DATA
   FOOD->**{DATA+2
   AMMO->**{DATA+4
   PARTS->**{DATA+6
   PACE->**{DATA+8
   RATION->**{DATA+10
   D->**{DATA+12
   E->**{DATA+14
   F->**{DATA+16
   H->**{DATA+18
   K->**{DATA+20
   L->**{DATA+22
   M->**{DATA+24
   T->**{DATA+26
   CloseAll
   Open("OREFILE","w"->ZZ
   Write(DATA,28,2,ZZ
   SetArchiveStatus(1,ZZ)
   Close(ZZ
Return

NOTES:
"Read(" and "Write(" will do so for SIZE*COUNT bytes
closeAll is usually at the very beginning and the very end of your program (it can be used inbetween of course)
The variable you are opening is only unarchived when you use a mode other than "r".
That seemed to do the trick! I didn't know that lists were buggy in ICE until now, I'll make a note to avoid them in the future. But anyways, thank you so much for helping me figure this out! I hope this topic will also help others with their endeavors in ICE.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
 
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 vote in polls in this forum

 

Advertisement