Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
I need some help writing to a variable in ICE using Write(. In essence I want to write a BASIC program in an ICE program. Therefore I need to be able to send tokens, variables, and numbers to the program via the Write( command. Preferably I could just use send over a string that contained the program. Here is what I have tried.


Code:
CloseAll
OpenVar("PROG","w+",5     //creating the BASIC program I want to write to
CloseAll     //I read in a thread that I should reopen new variables before writing to them
OpenVar("PROG","w",5     //opening the program. I couldn't store the slot using the → arrow, so I assume the slot is automatically 1
"Data to send over as a string..."→Str1    //storing the string I want to send over
GetSize(Str1)→SIZE     //This is probably an issue since GetSize( is supposed to use a slot instead of a variable. However, I need to find out the size of my string
Alloc(SIZE)→DATA   //allocating enough space for my string at the pointer DATA
Copy(DATA,Str1,SIZE   //copying my string into DATA
Write(DATA,SIZE,1,1    //writing my DATA to the program
1. To get the size of a string, use length(STRING)->SIZE.
2. You have to keep the slot open if you wish to use it, you close it when you are all done
3. You can use Write(Str1,SIZE,1,SLOT)
4. See example code below:

Code:
CloseAll
OpenVar("PROG","w",4)->PROG
"DATA TO SEND"->Str1
length(Str1)->SIZE
Write(Str1,SIZE,1,PROG)
CloseAll

Please keep in mind that programs have different means of data formatting.
Okay, so I used that code and can send letters over to the program. But tokens get messed up. Is there a way for me to send tokens to the program?
Tokens are a bit different. You know how I said that programs have a different format? Well tokens follow that format. To send tokens, you have to use '. For example

Code:

CloseAll
OpenVar("PROG","w",4)->PROG
'Str1'->Str1
length(Str1)->SIZE
Write(Str1,SIZE,1,PROG)
CloseAll


This should send the Str1 token to the program.
dankcalculatorbro wrote:
Okay, so I used that code and can send letters over to the program. But tokens get messed up. Is there a way for me to send tokens to the program?


Use the single quote, and ICE will use the raw data data in the string, else if you use the double quotes it will change the data into (semi) standard ascii.
I decided to try to learn more about writing to variables in ICE so that I can make a save feature for my games. So as an exercise I'm making a simple program editor. I got stuck on listing all the programs on the calc. Using the code given in the documentation, I came up with this.

Code:
det(0
det(5,255
0->POS
10->Y
While DetectVar(°POS,0,5)->PROG
OpenVar(PROG,"r",5)->SLOT
Y+10->Y
PrintStringXY(PROG,10,Y
End
Pause
det(1

However, the name is not printed unless I get rid of the OpenVar(. I need the slot though, so I can't get rid of the OpenVar(. Why is the name not printed? Also, when I got it to print (without the OpenVar) one program was named "#" and another "!". Why is that?
When I created my shell I had the same issue. To get the name of the variable, insert the following code:

Code:
Copy(Str1,PROG,length(PROG)+1)


The problem lies with the null termination. Adding the +1 solves that. To view the program name, simply display Str1

I too see the weird program names. I attribute this to a byproduct of Cesium The OS (totally got that right the first time), but this is most likely untrue. Just know that an application The OS on your calculator creates these.

Hope this helps!
Thanks, I got it working. However, I have run into more problems. The code I use to display if a program is archived or not always displays the program is archived.

Code:
0->POS
10->Y
While DetectVar(°POS,0,5)->PROG
OpenVar(PROG,"r",5)->SLOT
Y+10->Y

//the problem code
If IsArchived(SLOT)
PrintStringXY("*",5,Y
End

PrintStringXY(PROG,10,Y
End

On a side note, how do I write a line break into a program (besides using ":").
dankcalculatorbro wrote:
Thanks, I got it working. However, I have run into more problems. The code I use to display if a program is archived or not always displays the program is archived.

Code:
0->POS
10->Y
While DetectVar(°POS,0,5)->PROG
OpenVar(PROG,"r",5)->SLOT
Y+10->Y

//the problem code
If IsArchived(SLOT)
PrintStringXY("*",5,Y
End

PrintStringXY(PROG,10,Y
End

On a side note, how do I write a line break into a program (besides using ":").


The hex codes for all of the tokens in a string or prgm can be found here: http://tibasicdev.wikidot.com/one-byte-tokens

The hex code for a new line is 3F, so use PutChar and [E]3F ([E] is the small capital E)
beckadamtheinventor wrote:
dankcalculatorbro wrote:
Thanks, I got it working. However, I have run into more problems. The code I use to display if a program is archived or not always displays the program is archived.

Code:
0->POS
10->Y
While DetectVar(°POS,0,5)->PROG
OpenVar(PROG,"r",5)->SLOT
Y+10->Y

//the problem code
If IsArchived(SLOT)
PrintStringXY("*",5,Y
End

PrintStringXY(PROG,10,Y
End

On a side note, how do I write a line break into a program (besides using ":").


The hex code for a new line is 3F, so use PutChar and [E]3F ([E] is the small capital E)


It's actually |E in SC3
# and ! are OS artifacts you dimwits.
  
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