Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: p2 on August 24, 2011, 09:49:49 am

Title: string - duplicate symbol
Post by: p2 on August 24, 2011, 09:49:49 am
I'm trying to write a "chat-program" for the TI, but I have a problem:
If I want to write something, I'll have to edit the string!
But how can I save something in a String if ther's alreadsy saved something in it?
Code: [Select]
:DelVar Str00
:"abc" -> Str00
Isn't working

but sometimes, I deed olly to add one letter to String00! How to do that???
It allways tells me DUPLICATE SYMBOL
Title: Re: string - duplivate symbol
Post by: JosJuice on August 24, 2011, 09:59:59 am
Str, Pic and GDB in Axe can only be set to a value when you're creating a program - you can't change the value of them while running the program. You'll need to use a free piece of RAM instead.
Title: Re: string - duplivate symbol
Post by: AngelFish on August 24, 2011, 10:42:47 am
I'm trying to write a "chat-program" for the TI, but I have a problem:
If I want to write something, I'll have to edit the string!
But how can I save something in a String if ther's alreadsy saved something in it?
Code: [Select]
:DelVar Str00
:"abc" -> Str00
Isn't working

but sometimes, I deed olly to add one letter to String00! How to do that???
It allways tells me DUPLICATE SYMBOL

You need to do something like
Code: [Select]
:Zeros(Str1,3)
:"abc"->Str1
To get that to work (Assuming you can store a string to memory in axe). Most Axe variables are *not* like TI-BASIC variables. They're created at compile time, which means that if you were to store more information to them than was originally placed there, you'd either corrupt RAM or overwrite part of your program.
Title: Re: string - duplivate symbol
Post by: Deep Toaster on August 24, 2011, 10:50:06 am
Code: [Select]
:Zeros(Str1,3)
:"abc"->Str1
That won't work either, because Zeros() already creates the static variable Str1 (three null bytes). Instead, do either this:
Code: (Axe) [Select]
:Copy("abc",Str1,3)or
Code: [Select]
:'a'→{Str1}
:'b'→{Str1}
:'c'→{Str1}
to put "abc" in a Str1 that already exists.
Title: Re: string - duplicate symbol
Post by: p2 on August 24, 2011, 11:38:47 am
and when I want to add a single letter to a string?
How to do that?
Title: Re: string - duplicate symbol
Post by: Michael_Lee on August 24, 2011, 11:59:57 am
Try making the length of Str1 much larger then you need it to be -- I don't think it's easy to change the size of a constant after it's declared.
Code: [Select]
Zeros(50)->Str1

Copy("String 1",Str1,8)
Copy("The next string",Str1,15)

Alternatively, you could use either a buffer (like L1, L2, etc.) or an appvar.
This might not work/probably needs tweaking, but try something like:
Code: [Select]
Zeros(700)->L1
"Hello World!"->L1
Text(10,10,L1)
"Goodbye"[00]->L1
Text(10,20,L1)
(The [00] adds a null byte, just in case)

Also, I'm trying to remember -- if you compile as an app, can you rewrite program memory like Str1 or Pic02?

Edit:
Changed 'Zero(pointer,size)' to 'Zero(size)->pointer'
Title: Re: string - duplicate symbol
Post by: Deep Toaster on August 24, 2011, 12:02:53 pm
Also, I'm trying to remember -- if you compile as an app, can you rewrite program memory like Str1 or Pic02?
Nope, but you can always use safe RAM like L1.
Title: Re: string - duplicate symbol
Post by: Runer112 on August 24, 2011, 12:07:13 pm
I'm not sure why everyone has been using Zeros(pointer,size) in their code. This is not valid syntax. Zeros() only takes a single argument, and that is size. You want to use Zeros(size)→pointer instead.
Title: Re: string - duplicate symbol
Post by: Michael_Lee on August 24, 2011, 12:23:56 pm
I'm not sure why everyone has been using Zeros(pointer,size) in their code. This is not valid syntax. Zeros() only takes a single argument, and that is size. You want to use Zeros(size)→pointer instead.

Erm, I was copying Deep Thought who (I suspect) was copying Qwerty.

>.>

*Michael hides
Title: Re: string - duplicate symbol
Post by: yrinfish on August 24, 2011, 01:44:31 pm
Two things, first @DT:
Code: [Select]
:'a'→{Str1}
:'b'→{Str1}
:'c'→{Str1}
to put "abc" in a Str1 that already exists.

That should be:
Code: [Select]
:'a'→{Str1}
:'b'→{Str1+1}
:'c'→{Str1+2}

otherwise the first char would be overwritten with a, then b and finally c...

second, to add only one, do this:
Code: [Select]
:'a'→{Str1+<offset>}
Title: Re: string - duplicate symbol
Post by: AngelFish on August 24, 2011, 01:53:04 pm
I'm not sure why everyone has been using Zeros(pointer,size) in their code. This is not valid syntax. Zeros() only takes a single argument, and that is size. You want to use Zeros(size)→pointer instead.
/me is launching a covert campaign to get Quigibo to change the syntax...
Title: Re: string - duplicate symbol
Post by: Deep Toaster on August 24, 2011, 03:23:26 pm
I'm not sure why everyone has been using Zeros(pointer,size) in their code. This is not valid syntax. Zeros() only takes a single argument, and that is size. You want to use Zeros(size)→pointer instead.
Copied from Qwerty. Wasn't thinking.
That should be:
Code: [Select]
:'a'→{Str1}
:'b'→{Str1+1}
:'c'→{Str1+2}
Again, wasn't thinking x.x
Title: Re: string - duplicate symbol
Post by: p2 on August 25, 2011, 08:55:29 am
so that should be possible: ???
Code: [Select]
:{Str1+X}→{Str2+(lenth(Str1)+1)}

I've used a String (Str60) for the Free spaces - To delete a string I now use
Code: [Select]
:Copy(Str60,[i]Str2[/i],90) (90 because str60=90 spaces)





this is my newest code:
(You must read it to understand the program - No (english) description in it!!)
Spoiler For code:
:.CHAT
:"                                                                                "→Str60
:det(500)→Str1
:det(500)→Str2
:5→B
:"person:"→Str80
:"p1 = [1]"→Str81
:"p2 = [2]"→Str82
:Output(1,1,Str80
:Output(2,1,Str81
:Output(3,1,Str82
:Repeat B=1
: If getKey(34)
:  1→X
:  1→B
:  Goto 1
: End
: If getKey(26)
:  2→X
:  1→B
: End
:End
:
:
:Lbl 1
:
:
:1→A
:ClrDraw
:DispGraph
:
:
:
:
:
:
:
:
:
:
:
:Repeat getKey(15)
:
:
:
:
:
:
:
:.EMPFANGEN/
:
:Get(→Ans
:If Ans≠(0-1)
: Vertical -
: Vertical -
: Vertical -
: Vertical -
: Vertical -
: Vertical -
: Vertical -
:
:
: Text(0,40,Ans
: If X=1
:  conj(Str60,Str2,90)
: End
: If X=2
:  conj(Str60,Str1,90)
: End
:End
:
:./EMPFANGEN
:
:
:
:
:
:
:.SENDEN/
:
:If getKey(9)
: If X=1
:  Repeat Send(Str1,2000)≠(0-1)
:  End
:  Vertical -
:  Vertical -
:  Vertical -
:  Vertical -
:  Vertical -
:  Vertical -
:  Vertical -
:  Text(0,40,Str1
:  conj(Str60,Str1,90)
: End
: If X=2
:  Repeat Send(Str2,2000)≠(0-1)
:  Vertical -
:  Vertical -
:  Vertical -
:  Vertical -
:  Vertical -
:  Vertical -
:  Vertical -
:  Text(0,40,Str2
:  conj(Str60,Str2,90)
: End
:End
:
:./SENDEN
:
:
:
:
:
:
:.FENSTER/
:
:For(P,0,95
: For(Q,5,63
:  Pxl-Off(P,Q
: End
:End
:If getKey(1)
: Vertical -
:End
:If getKey(2)
: Horizontal +
:End
:If getKey(3)
: Horizontal -
:End
:If getKey(4)
:Vertical +
:End
:If getKey(1)=getKey(2)=getKey(3)=getKey(4)=1
: ClrDraw
: If X=1
:  Text(0,50,Str1
: End
: If X=2
:  Text(0,50,Str2
: End
:End
:If X=1
: Text(0,50,Str1
:End
:If X=2
: Text(0,50,Str2
:End
:
:./FENSTER
:
:
:
:
:
:
:.DEL/
:
:If getKey(56)
: If X=1
:  conj(Str60,Str1,90)
: End
: If X=2
:  conj(Str60,Str2,90)
: End
:End
:
:./DEL
:
:
:
:
:
:
:.MODUS/
:
:If getKey(55)
: A+1→A
: If A=4
:  1→A
: End
:End
:If A=1
: conj("         'WRMH  ?θVQLG  :ZUPKFC  YTOJEB  XSNIDA         ",Str99,56)
:End
:If X=2
: conj("         'wrmh  ?θvqlg  :zupkfc  ytojeb  xsnida         ",Str99,56)
:End
:If X=3
: conj("         +-*/^  ‾369)}  .258(K  0147,       2-1          ",Str99,56)
:End
:
:./MODUS
:
:
:
:
:
:
:.SCHREIBEN/
:
:For(Z,10,56
: If getKey(Z)
:  If X=1
:   conj({Str99+Z},Str1,length(Str1)+1)
:   Text(0,50,Str1
:  End
:  If X=2
:   conj({Str99+Z},Str2,length(Str2)+1)
:   Text(0,50,Str2
:  End
: End
:End
:
:./SCHREIBEN
:
:
:
:
:
:
:.ZEIGE/
:
:If X=1
: Text(0,50,Str1
:End
:If X=2
: Text(0,50,Str2
:End
:./ZEIGE
:
:
:
:
:
:
:
:End
:
:
:
:
:.LEAVE/
:
:If X=1
: conj(60,Str1,90)
: conj("p1 has left TItalk",Str1,18)
: Send(Str1,5000
:End
:If X=2
: conj(Str60,Str2,90)
:  conj("p2 has left TItalk",Str2,18)
: Send(Str2,5000
:End
:
:./LEAVE