Is there some way to communicate calc-to-calc in ICE (sending/receiving variables)? I am trying to write a multiplayer game, and I think it would look best if done in ICE because it is a visual-based game, so the great graphics options that ICE provides would be really useful. If such code does not exist, I guess I'll just stick with BASIC Razz
No. It may soon, but not yet.
In that case, can I also ask if you store values into L1 outside of ICE, can you then access those values in ICE using L1(<index>)?
No.
Argus wrote:
In that case, can I also ask if you store values into L1 outside of ICE, can you then access those values in ICE using L1(<index>)?

Alternatively, you can use this:

Code:
sum(2,'L₁',"r",1)→LIST
//LIST now contains a pointer to the L₁ variable
Quote:
Alternatively, you can use this:


Code:
sum(2,'L₁',"r",1)→LIST
//LIST now contains a pointer to the L₁ variable


Thanks, I'll try using this then. Though it may not be needed due to the new designs I'm working on...
Another question! (this should be my ICE questions list...) How could I convert a string to an int?
Check the program ICECONSI.8xp here for an example I made.
Is there a limit to how much data can be written to an Appvar at a time because when I write only 3 characters to it, it works fine. But when I write 34, it doesn't seem to work because reading it out, the string is empty.

Edit: It seems the max is 7 chars at a time? That's what seems to be it.

Final edit: My real question should be, how could I write a string of any length 34 thru 5000 to a new Appvar? So far I've been trying to write the string "00000000000000000000000000000000000000" (38 zeros) to the Appvar STATS and read it out into Str1, but I can't figure out why my code won't work.

Code:
"00000000000000000000000000000000000000"→Str1
length(Str1)→L
sum(0
sum(1,"STATS", "w+")→A
sum(4,Str1,L,1,A

sum(1,"STATS","r")→A
sum(5,Str1,38,1,A

det(0
det(18,Str1,3,3
Pause 2000
det(1
Argus wrote:
Is there a limit to how much data can be written to an Appvar at a time because when I write only 3 characters to it, it works fine. But when I write 34, it doesn't seem to work because reading it out, the string is empty.

Edit: It seems the max is 7 chars at a time? That's what seems to be it.

Final edit: My real question should be, how could I write a string of any length 34 thru 5000 to a new Appvar? So far I've been trying to write the string "00000000000000000000000000000000000000" (38 zeros) to the Appvar STATS and read it out into Str1, but I can't figure out why my code won't work.

Code:
"00000000000000000000000000000000000000"→Str1
length(Str1)→L
sum(0
sum(1,"STATS", "w+")→A
sum(4,Str1,L,1,A

sum(1,"STATS","r")→A
sum(5,Str1,38,1,A

det(0
det(18,Str1,3,3
Pause 2000
det(1

To return the string correctly when reading/writing, you must increment the variable L by 1. The string "HELLO" actually contains "HELLO\0" (a null terminator) and that null terminator must be copied as well.
Also, I have not been able to get the 'Read' ( 'sum(5,' ) command working with strings. I have always had to use pointers and then copy the data to a string.
On top of that, ALWAYS make sure to close a slot before reopening it again (you opened slot A twice), and preferably allocate space in a variable before using it with 'Read'
Lastly, you should ALWAYS use single quotes when writing to an AppVar, to avoid ASCII mismatches, string squishing, and the subsequent loss of some or all readable data

Try this (UNTESTED, so preferably in CEmu):

Code:
'00000000000000000000000000000000000000'→Str1  // ALWAYS use single quotes when writing to an AppVar
length(Str1)+1→L                               // Add terminating 0 to length
Alloc(L)→DATA                                  // Allocate L bytes and return a pointer in variable DATA

sum(0
sum(1,"STATS","w+")→A
sum(4,Str1,L,1,A

sum(3,A                                        // Close slot A
sum(1,"STATS","r")→A
sum(5,DATA,L,1,A                               // Read AppVar into pre-allocated variable DATA

Copy(Str1,DATA,L                               // Copy all data from DATA into Str1

det(0
det(18,Str1,3,3
Pause 2000
det(1


EDIT: You probably should rename this thread, due to the wide variety of questions you are asking here
Thanks! I spent a couple of hours trying to find a solution to my problem without an answer, and although I did get pretty close, it always failed. Your explanation should help me figure out what has been going wrong so far. Also, I don't think you can rename a thread, I believe only moderators can do that.
Argus wrote:
Thanks! I spent a couple of hours trying to find a solution to my problem without an answer, and although I did get pretty close, it always failed. Your explanation should help me figure out what has been going wrong so far. Also, I don't think you can rename a thread, I believe only moderators can do that.

You just have to edit the first post and change the subject at the top (although I think you figured that out) Razz
So, what if I tried to read out all data from an Appvar, without knowing the length? (Then store it all in Str0)
Argus wrote:
So, what if I tried to read out all data from an Appvar, without knowing the length? (Then store it all in Str0)


Just have some reference to the size of the string before the string. Write the size of the string first, which will be a 3-byte int since you're in ICE. Then store everything to a string (str1 in this case) and write that to the appvar, using the write command, which would look like this:

Code:
"Test"->str1
4->SIZE
CloseAll()
Open("APPVAR", "w")->SLOTA
Write(SIZE, 3, 1, SLOTA)
//size is 1 * number of characters, where each character takes up 1 byte of memory
Write(str1, 4, 1, SLOTA)

Then to read it back out:

Code:
CloseAll()
Alloc(3)->SIZE
Open("APPVAR", "r")->SLOTA
//^^o is the degree sign
Read(^^oSIZE, 3, 1, SLOTA)
Read(str0, SIZE, 1, SLOTA)

There may be some syntax issues, since I have switched to C and haven't used ICE in a while, but this is the general way to do it. Let me know if you have more questions.
Of course! I used this in other parts of my program (reading out strings of certain lengths) but it didn't occur to me to use it for the entire appvar. Thanks!
epsilon5 wrote:
Argus wrote:
So, what if I tried to read out all data from an Appvar, without knowing the length? (Then store it all in Str0)


Just have some reference to the size of the string before the string. Write the size of the string first, which will be a 3-byte int since you're in ICE. Then store everything to a string (str1 in this case) and write that to the appvar, using the write command, which would look like this:

Code:
"Test"->str1
4->SIZE
CloseAll()
Open("APPVAR", "w")->SLOTA
Write(SIZE, 3, 1, SLOTA)
//size is 1 * number of characters, where each character takes up 1 byte of memory
Write(str1, 4, 1, SLOTA)

Then to read it back out:

Code:
CloseAll()
Alloc(3)->SIZE
Open("APPVAR", "r")->SLOTA
//^^o is the degree sign
Read(^^oSIZE, 3, 1, SLOTA)
Read(str0, SIZE, 1, SLOTA)

There may be some syntax issues, since I have switched to C and haven't used ICE in a while, but this is the general way to do it. Let me know if you have more questions.

Alternatively, you can use GetSize(), which will return the size of the AppVar (or anything else) in SLOTA:

Code:
sum(16,SLOTA)
calclover2514 wrote:

Alternatively, you can use GetSize(), which will return the size of the AppVar (or anything else) in SLOTA:

Code:
sum(16,SLOTA)

Yeah, but that gets the size of the whole appvar, not the string. To get that to work, the string itself would have to be in a slot, and I'm not sure that works for the strings in ICE (although you can do that for the OS strings).

EDIT: Does sum(16,Str1) work?
EDIT 2: No it doesn't, never mind.
But in C, all you'd have to do is sizeof(str1)...
epsilon5 wrote:
calclover2514 wrote:

Alternatively, you can use GetSize(), which will return the size of the AppVar (or anything else) in SLOTA:

Code:
sum(16,SLOTA)

Yeah, but that gets the size of the whole appvar, not the string. To get that to work, the string itself would have to be in a slot, and I'm not sure that works for the strings in ICE (although you can do that for the OS strings).

EDIT: Does sum(16,Str1) work?
EDIT 2: No it doesn't, never mind.
But in C, all you'd have to do is sizeof(str1)...

Ummm . . . length(Str1) works in ICE v2.2.
Source: https://petertillema.github.io/ICE/commands.html#strings

EDIT:
So you could do something like this:

Code:
sum(16,SLOTA)→L
Alloc(L)→DATA
sum(5,DATA,L,1,SLOTA
length(DATA)→STRLEN

Which would return the length of the string in the variable SLOTA up to the null terminator in STRLEN.
Right, forgot about that command. Like I said, I haven’t used ICE in a while. In that case, the best implementation in my opinion would be to write like this:

Code:
"Test"->str1
Length(str1)->SIZE
CloseAll()
Open("APPVAR", "w")->SLOTA
Write(SIZE, 3, 1, SLOTA)
//size is 1 * number of characters, where each character takes up 1 byte of memory
Write(str1, 4, 1, SLOTA)

Then use the reading code I posted earlier to read it back out. I think that using getsize for this wouldn’t work, since that would get the size of the whole appvar, including all of the strings to be read. I assume Argus wants to have more than one string in each appvar. If not, that would work though.
I only used GetSize() because it would work if you wanted to store all the strings in one variable and then parse them one at a time, therefore minimizing the number of Read() operations and make the code smaller. This would work because length() only reads the string to the first null terminator ($00)
  
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 2
» 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