-
any one think this should be the big talked about command in basic? It alows you to do all kinds of things, from self modifying code to very advanced optimisations.
Ok...this doesn't work...
Here, this one is a bit more complex example
You could store into String1 "1,16(A-1),16(B-1),2,16," and "0,0,0" into String3, and do an asm preproccess to take a matrix and make it into a string of "which pic to use, which row, and which column"
:For(A,0,4
:For(B,0,6
:real(String1+String2+String3
:End
:End
Fixed well...that would work...but it doens't use expr :dang:
************************************************
Ok, if enemy had a defense of 40, and was weak to fire...
"(1st:weak to fire?,2nd:Def,3rd=Health
"1,040,H"->String1
And if attacked
"weilding the Fire Sword of Bonus Damage"
"100*2("+sub(String1,1,1)+")-"+sub(String1,3,3)
expr(H-Ans
Well, that would do a bunch of crap...but H would be -160 as a result of "100*2(1)-040"... :imbeciles:
ok...that example was :beurk:
...but I hope you got the picture
well, discuss...
-
QuoteBegin-necro+27 November 2005, 19:29<table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td><b>QUOTE</b> (necro @ 27 November 2005, 19:29)</td></tr><tr><td id="QUOTE">QuoteEBegin any one think this should be the big talked about command in basic?
-
yes...you could optimise a 16X16 basic tile mapper that way. (what I want help doing for LOZNA) Prgm stuff won't work...my bad ):
-
still pretty cool stuff
-
some one needs to add that to ti-os...
-
OMG I didn
-
very nice necro, this should be really useful :)
-
and I learned it just Friday...any ways, in rpg, this is a great way to add multipliers, resistances/weaknesses, etc...also, this could be quite useful in complex magic systems...all kinds of uses realy.
I am trying to find out what commands screw it up...so far, prgm***** ,asm(***** ,and real(xlibstuff***** commands.
OH...NOTE: real(string1 does work as a xlib command set...but if real is in expr("____" it will work like the normal math command
-
very nice, I should try this out :)
-
wow, this is cool! I never thought to do that...
-
seems like it might open a new door for self modifying code in BASIC :D
-
yep, I just hope it doesn't lead to overly complex/ unmanagable code
-
You guys figured this out just now? I've been using this for a year.
-
what? you should have posted about it :?
maybe other ppl wanted to know a long time before :x
still cool though because I didnt knew about this
-
i actually knew about it, just didn't exploit it to its full potential yet. Go Necro!! anyways, i use it in my zelda text decoder, (inspired by spellshapers) the first number in the screen is how much collums down will display text. thus, u can set up a text box using expr(. :)
-
I believe I did mention something about this in the Aura thread a while ago...
-
I
-
QuoteBegin-dysfunction+29 November 2005, 8:03-->
QUOTE (dysfunction @ 29 November 2005, 8:03) |
I believe I did mention something about this in the Aura thread a while ago... |
uh where? I guess that might be in a topic from last year in EPS forums or Maxcoderz or I might have missed some new posts here once
-
Okay, here's a REAL example :P

In an old project of mine (theta twelve) I used lists for loading, so I had a variable for the 4 char listname, but! it twas a lot of code to indivudaly load EACH list into L1, so I did this
:"L10AL11AL12AL13AL13A...->Str1
then I did
:expr("/L/"+sub(Str1,L4-4,4->L/1/
basically, I took the list (named in Str1) added "/L/" (the little L for lists) and exicuted it, then stored it to L1 :D
yay space savers!
-
wow... i gotta look into using this...
-
Wow, this is pretty cool. And I understand it!!! YAY FOR UNDERSTANDING!!!
-
this is going into my new RPG
-
^^
-
"WOOT" owly says...
..~'~..
-
I think your attempt at imitating blub icon failed litterally here
-
>(<') go blub
-
~~>(<.)~~ blub died...
just kiding (^>)<
-
I wish there was a command to store real numbers into a string- expr( converts a string into numbers (or commands), but there is no equivalent command to store a number into a string. Of course, to store the number in, say, variable A into Str1, you could do this:
c1-->CODE |
ec1 sub(Str2,A+1,1) -> Str1c2 |
ec2
Where Str2 is "0123456789"
But this becomes rather slow, especially if you then have to deal with two-digit or larger numbers.
-
hmmmm, is it possible to have a compressed save file as a string, most games i kno use lists, but if u were to use a string...
-
Sure you can use strings, but it would be a bit slower to save (no real speed difference for loading), and also you only have a limited number of strings, whereas lists can have custom names.
-
strings should not be used to save...period. Play another game and you'd loose all progress...L1-L9 should also not be used...
-
Err... L1-L6
and you could say... use a string and use a method to compress it into a list (it's not that hard :D
)
-
Would expr( work for RecallPic X:
"0123456789
expr("RecallPic"+sub(Ans,X+1,1
-
give it a shot
-
QuoteBegin-tenniskid493+14 December 2005, 8:07-->
QUOTE (tenniskid493 @ 14 December 2005, 8:07) |
Would expr( work for RecallPic X:
"0123456789 expr("RecallPic"+sub(Ans,X+1,1 |
no :(

-
nope....oh well.
-
QuoteBegin-xlibman+14 December 2005, 11:28-->
QUOTE (xlibman @ 14 December 2005, 11:28) |
QuoteBegin-tenniskid493+14 December 2005, 8:07-->QUOTE (tenniskid493 @ 14 December 2005, 8:07) | Would expr( work for RecallPic X:
"0123456789 expr("RecallPic"+sub(Ans,X+1,1 |
no :(  |
i'm assuming it will work with xlib's recall pic function though, real(3,X,0,1) :)

-
Yeah that should be just fine. :)
The reason it won't work with RecallPic is because RecallPic VAR doesn't work, it has to be a number.
-
yeah, it dosen't work with like 70%+ of the commands you want it to work with
-
It doesn't work for storing, for one thing:
c1-->CODE |
ec1 {1,2,3} -> expr("L"+"1")c2 |
ec2
Doesn't work.
-
that may make things a bit interesting
-
yep, it has problems with the -> command inside of strings, something the tios is finiky about
But expr("{1,2,3}->L1 one works...so sometimes things need to get very complicated to get the desired effect
-
Maybe we should just go through and list the commands that expr( doesn't like...?
-
and make a tutorial for undocumented tricks with expr( :D

there are still lot of stuff I dont know about BASIC I think :D
-
Well...
StorePic
RclPic
UnArchive
Archive
those are the ones I really needed... but don't work
-
And of course anything with a -> in it, since Sto automatically closes parentheses or quotation marks behind it.
-
xlib can use the ANS command, but there is currently a nasty bug if ANS is empty when you do it
-
oh I see, I assume its better to store 0 to ans by default at game startup in case
-
u guys think we should change this forum so its an overall BASIC tricks forum kinda like wat UTI has? thatd be useful :)
-
hmm maybe that would be a good idea. It might become a mess after a while though if we make this topic general, people would post the same tricks over and over after a while. What do you guys think we should do?
-
what about only letting staff and managers post stuff in this section? and submissions from members and RPG coders have to be approved?
or: make a thread for gathering ideas and tricks, then make a thread where only staff can post, where the useful information is put into and explained.
-
I might create a section just for BASIC and one for ASM/C, its pretty hard to decide, since not much people ask help here yet. Or I will rename this topic. Members should be able to share their ideas as well
-
I like the renaming thing and letting people post submissions about everything. Staff/Managers could just go through and make sure no one posts the same trick twice. I wouldn't mind keeping track of that.
-
done
-
moved to programming help
-
I got a question: what does instring( do? :???:
-
from wat the book saids: itll return the character position in string of the first character of substring.
instring( string, substring(, where to start looking).
id ask tifreak8x, as i saw it used in his code :)
, but my guess is u can use instring to find the location of specific characters and use that for hit detection.
-
ah I see...
-
InString("ABCDEFGHI","FG" will return 6, since that is where it starts at. If you take:
If not(InString("ABCDEFGHI",sub(Str1,T-1,1):Then:etc...
This is the basic syntax of hit detection when going left for strings. Look at my walking engine for more examples on the pokemon beta. :)
-
I
-
No problem, I hope you understand it... :D
-
yeah, now I do >D
-
Glad I could be of help. :)
-
now i've got a few questions, at the UnitedTi forum, there's a lot about max speed in basic. i'd like to know if they're true.
-are if-then statements faster than if statements?
-The more free ram, the faster the prgm will run?
-too much prgm in prgm menu, will run slower?
-does optimising improve speed, ex: not(A, A=0
-is while faster or repeat loops
Thanks if u can help...:)
-
If statements are faster, here is why:
Everytime the calculator sees a Then statement, or a loop, it registers how many End statements it sees. This of course takes little processing power (I think) but over a long period, it can cause a slow down, hence the memory leaks. If you just use an If statement, it doesn't need to worry about an End statement... Using an If statement only allows 1 command to be used, though, so watch yourself.
If I remember correctly, the amount of RAM does not slow down or speed up a program.
Actually, this will slow a program down a little, because that means it has to search the VAT entries for more programs.
Some optimizing does, but others can actually slow down a game.
If K=25:Then is actually faster then A-((K=25)-(K=26))->A because it is looking for the K with an If statement, but with the equation, it actually keeps doing the equation over and over. If K does not =25, then it ignores what ever comes after it. :)
I honestly don't know of a speed difference between the two, but there could be, if someone else here knows...
-
Both While and Repeat Loops are equal in speed. I believe Arcane Wizard answered that at UnitedTi. I'll try to find the link.
EDIT: Fixed it.
-
Don't you mean while and repeat?
-
Yup, sorry about that.
-
another questions: which are faster: subroutines or if-then statements?
-
If:Then's are faster than subroutines. However, if you are doing the same thing inside the If:Then statement multiple times, you could save a lot of space by using subroutines. Its sort of a trade off.
-
anyone kno some cool optimisations using boolean logic (xor, or, and, not). one that i kno that toggles the number would be:
:N(A=0)->A
this will toggle A from 0 to the number(N). anyone kno more?
-
For my walking engine, I used:
X-8(K=24)+8(K=26)->X
Y-8(K=25)+8(K=34)->Y
EDIT: Wait nvm, your the one who gave me that.
-
All sorts of (), +, and = combinations can replace and/or.
Someone should make a Boolean converter for long expressions.
---EDIT---
And subtraction might be able to replace xor.
-
wat do u mean? and ive got another question, will variable inputs run slower, faster, or same speed, for instance,
real(3,0,0,1
or
real(3,A,A,1 where A=0
-
I believe they run the same, however I am not positive on that.
I belive what Radical Pi meant was that instead of doing
c1-->CODE |
ec1If X=1 and Y=3 Z+15->Zc2 |
ec2
You can do
c1
-->CODE |
ec1Z+15(X=1)(Y=3)->Zc2 |
ec2
If thats not what you meant, post an example.
-
Like I said in my earlier post, that can actually slow the game down, if you use a lot of them, since it has to do all the calculations every loop...
-
Yeah I tried to optimize my TBS engine with those, and it ended up running at almost exactly the same speed. Booleans are faster than If:Then only if you don't have extremely complicated movement routines.
-
Yes, I meant exactly that.
I don't think my games are slowed by it that much, I only use it for moving left/right/up/down.
-
Ok, good. I had to try to guess at what you meant. I have a few of those in my game but, like tifreak8x said, if you use to many of them, they can do more harm than good.
-
I would love for an assembly coder to go in CalcSys or a debugger and see exactly how many clock cycles each of these commands takes and make a table, then we could just add up the cpu time required by each command in a routine to see which is faster.
-
y don't we ask that over at MC forums, maybe one of those asm gurus will do it? :)
-
Good idea, I think I will!
-
ok, today in math class, had a lot of time so did some testing on speed of stuff.here's wat i got
-(everyone except me probably knew this, but ANS work faster than the number)
-Using the real number instead of variable works faster, real(0 will work faster than real(A
-
Sweet. I never knew about the Ans thing. For the number faster than variable, it makes sense. Instead of having to search the VAT for the variable to get the value, it has the value provided for it immediately. Still good to know though.
-
Using ans is alright, but if you are doing any other equations, ans will be messed up. :)

Basically, ans is good for simple things (I use it for a program that has multiple routines, I just store the number to ans, call the program, then the first line in the program is Ans->L :)
That makes things a little smaller and faster...
-
trick to test if xlib is installed
1
real(0
not(Ans
If Ans:Pause "Install Xlib!
If Ans:Return
-
QuoteBegin-necro+4 January 2006, 21:36-->
QUOTE (necro @ 4 January 2006, 21:36) |
trick to test if xlib is installed
1 real(0 not(Ans If Ans:Pause "Install Xlib! If Ans:Return |
If you want to save a byte do
c1
-->CODE |
ec11 real(0 If not(Ans:Pause "Install Xlib! If not(Ans:Returnc2 |
ec2
Doesn't save much but hey 1 byte is a byte!
-
Check the code, it produces different results. Necro's produces 1, where yours produces 0.
-
QuoteBegin-tifreak8x+4 January 2006, 22:02-->
QUOTE (tifreak8x @ 4 January 2006, 22:02) |
Check the code, it produces different results. Necro's produces 1, where yours produces 0. |
Yes but it has the same effect....
-
yes, you unrapped a line break and as such, "not(...:not(..." is better than an "not(Ans:"...if I had a third line of conditionals in there, it would be better my way though
-
QuoteBegin-necro+4 January 2006, 22:21-->
QUOTE (necro @ 4 January 2006, 22:21) |
yes, you unrapped a line break and as such, "not(...:not(..." is better than an "not(Ans:"...if I had a third line of conditionals in there, it would be better my way though |
But there is a problem with both of ours, when you run it if xlib isn't installed then it says "Install Xlib!" but now the Ans is "Install Xlib!" so it receives a DATA TYPE error. So in order to stop that just place the first1 in a If Then
c1
-->CODE |
ec11 real(0 If not(Ans:Then Pause "Install Xlib! Return Endc2 |
ec2
Then just place the rest of the code after End (The rest of the program).
-
Indeed...but what about the whole Kitten-kaboodale (sp?)
:1
:real(0
:If not(Ans
:Then
:ClrHome
:Disp "PLEASE INSTAL XLIB BEFORE TRYING TO RUN THIS GAME
:Pause
:End
:If not(Ans
:Stop
-
QuoteBegin-necro+4 January 2006, 22:58-->
QUOTE (necro @ 4 January 2006, 22:58) |
Indeed...but what about the whole Kitten-kaboodale (sp?)
:1 :real(0 :If not(Ans :Then :ClrHome :Disp "PLEASE INSTAL XLIB BEFORE TRYING TO RUN THIS GAME :Pause :End :If not(Ans :Stop |
One thing disp doesn't wrap :P

.
c1
-->CODE |
ec1:1 :real(0 :If not(Ans :Then :ClrHome :Output(1,1,"PLEASE INSTAL XLIB BEFORE TRYING TO RUN THIS GAME :Pause :stop :Endc2 |
ec2
-
Also, you misspelled Install.
-
that's nice to know, Tr1pl1ea should include that peice of code in the readme so all games with xlib uses it :)
-
QuoteBegin-dragon__lance+6 January 2006, 23:43-->
QUOTE (dragon__lance @ 6 January 2006, 23:43) |
that's nice to know, Tr1pl1ea should include that peice of code in the readme so all games with xlib uses it :) |
Well if xlib gets turned into a basic xlib game app it will not need the code above.
-
I guess that is a vote for my proposal of making an xlib shell?
-
QuoteBegin-necro+6 January 2006, 23:59-->
QUOTE (necro @ 6 January 2006, 23:59) |
I guess that is a vote for my proposal of making an xlib shell? |
Oh well I have been for it just didn't want Pat getting tired of working on it.
-
Apparently expr( doesn't work with the Goto command either, that's a shame.
-
too bad :(

at least does it work with useful commands?
-
It does work with many useful commands.
On a slightly different topic, does anyone know a way in which I can jump to a section of program according to the number stored in a variable? Say variable A=5, is there a way to then Goto 5, or Goto 27 if A=27, etc?
-
No but you could do
c1-->CODE |
ec1A If Ans=1:Goto 1 If Ans=2:Goto 2 If Ans=3:Goto 3 .... etcc2 |
ec2
-
Depends on what you are doing, but you can use While statments like goto/lbl commands, by manipulating the variable values... :)

Just keep everything in one big loop, say like this:
While W>0
All your fancy While commands go here
End
Return
And if you want out of the loops, just delvar W... :)
Make sense?
-
QuoteBegin-tifreak8x+12 January 2006, 23:09-->
QUOTE (tifreak8x @ 12 January 2006, 23:09) |
Depends on what you are doing, but you can use While statments like goto/lbl commands, by manipulating the variable values... :)
Just keep everything in one big loop, say like this:
While W>0 All your fancy While commands go here End Return
And if you want out of the loops, just delvar W... :)
Make sense? |
Yeah and no memory leaks :P

.
-
my 2 cents...
int(log(#)+1 = How many digits the number is
example
Text(0,0,sub(" 00000000",1,8-int(log(S)+1)),S
will return an 8 digit number at 0,0 on the GS no matter what (if S's digits are less than 8)
-
That's very useful, thanks! I remember I was looking for something that would do that a while ago, but I don't remember exactly what for... but I'll remember that.
-
QuoteBegin-CDI+13 January 2006, 7:04-->
QUOTE (CDI @ 13 January 2006, 7:04) |
my 2 cents...
int(log(#)+1 = How many digits the number is
example
Text(0,0,sub(" 00000000",1,8-int(log(S)+1)),S
will return an 8 digit number at 0,0 on the GS no matter what (if S's digits are less than 8) |
nice trick, i'll probably use it sometime >D

i may sound so noobish for asking this, but wat exactly is a memory leak? just when u use lables/ gotos and amount of free mem goes down?
-
QuoteBegin-dragon__lance+13 January 2006, 22:05-->
QUOTE (dragon__lance @ 13 January 2006, 22:05) |
QuoteBegin-CDI+13 January 2006, 7:04-->QUOTE (CDI @ 13 January 2006, 7:04) | my 2 cents...
int(log(#)+1 = How many digits the number is
example
Text(0,0,sub(" 00000000",1,8-int(log(S)+1)),S
will return an 8 digit number at 0,0 on the GS no matter what (if S's digits are less than 8) |
nice trick, i'll probably use it sometime >D  i may sound so noobish for asking this, but wat exactly is a memory leak? just when u use lables/ gotos and amount of free mem goes down? |
I seen this on maxcoderz before and is nice, a memory leak I believe is when you use a loop of some kind like while or repeat, then within the loop use an exit which isn't from the main loop.
c1
-->CODE |
ec1 Lbl 1 While K!=105 getkey->K if Ans=21:Goto 1 endc2 |
ec2
This would give a bad memory leak (take up ram space I believe) if 2nd is pressed within the loop.
-
A memory leak is when the calc encounters a command that requires an End statement, but never reaches it. The reason is it keeps track of how many Ends there should be, and that eats up memory...
-
got a question:
Is there a difference between int( and iPart( ?
cause it seems to me that they give the same reults...
-
hmm... isn't int( for positive numbers? and iPart( for anything?
-
CDI is correct.
-
With the bases, here's one for the maximum number of digits in any base from any base (b is old base, n is old number, c is new base):
c1-->CODE |
ec1 iPart(dim(n)*ln(b)/ln(c)+1) c2 |
ec2
QuoteBegin-Spellshaper+14 January 2006, 7:19
-->QUOTE (Spellshaper @ 14 January 2006, 7:19) |
got a question:
Is there a difference between int( and iPart( ?
cause it seems to me that they give the same reults... |
iPart( goes towards 0, int( goes to the next lowest integer.
-
QuoteBegin-MathStuf+14 January 2006, 13:56-->
QUOTE (MathStuf @ 14 January 2006, 13:56) |
With the bases, here's one for the maximum number of digits in any base from any base (b is old base, n is old number, c is new base): c1-->CODE | ec1 iPart(dim(n)*ln(b)/ln(c)+1) c2 |
ec2 |
so if I do iPart(dim(42)*ln(13)/ln(10)+1) what will that do again?
-
QuoteBegin-CDI+14 January 2006, 15:41-->
QUOTE (CDI @ 14 January 2006, 15:41) |
QuoteBegin-MathStuf+14 January 2006, 13:56-->QUOTE (MathStuf @ 14 January 2006, 13:56) | With the bases, here's one for the maximum number of digits in any base from any base (b is old base, n is old number, c is new base): c1-->CODE | ec1 iPart(dim(n)*ln(b)/ln(c)+1) c2 |
ec2 |
so if I do iPart(dim(42)*ln(13)/ln(10)+1) what will that do again?
|
That will return the maximum amount of digits in base 10 that a 42 digit number in base 13 can take up (which is 47). But n should be either a string (change to length( in that case) or a list for dim( to work properly).
-
Thanks for the "please install xLIB first thing" I just used it in my MS clone.