Hey all, I'm attempting to write a Rogue-like RPG in TI-BASIC. I've gotten basic movement and mapping done, as well as a semi-functioning menu. However I'm having some issues with the inventory system. The idea is that items will be randomly generated, so I need a way to dynamically retrieve the text data required for the name. I have code so far that reads the values from a list, looks for the index in a string, strips any unnecessary spaces, then concatenates the name in a for loop. My only issue is with speed. So my question is, is there a better way to go about doing something like this? Or can the code be optimized in any way?

Code:

ClrDraw:AxesOff
{3,2,5.1,2,3,5.2,4,5,1.2→L₁
"001BERSERKER 002KNIGHT    003ROGUE     004ARCHER    005MAGE      006AXE       007SWORD     008DAGGER    009BOW       010STAFF     011CHAINMAIL 012PLATEMAIL 013BRIGANDINE014GAMBESON  015ROBE      016BURN      017FREEZE    018PARALYSIS 019POISON    020CURSE     "→Str0
"001NEUTRAL   002FIRE      003ICE       004LIGHTNING 005EARTH     006SHADOW    "→Str1
"001COMMON    002RARE      003EPIC      004LEGENDARY "→Str2
DelVar L
For(I,1,dim(L₁),3
iPart(L₁(I+2)→J
10fPart(L₁(I+2)→K
sub(Str2,3+inString(Str2,sub("0123456789",iPart(L₁(I)/100)+1,1)+sub("0123456789",10fPart(iPart(L₁(I)/10)/10)+1,1)+sub("0123456789",10fPart(L₁(I)/10)+1,1)),10)
If " "=sub(Ans,length(Ans),1)
Then
While " "=sub(Ans,length(Ans),1
sub(Ans,1+(" "=sub(Ans,1,1)),length(Ans)-1→Str3
End
Else
Ans→Str3
End
sub(Str1,3+inString(Str1,sub("0123456789",iPart(L₁(I+1)/100)+1,1)+sub("0123456789",10fPart(iPart(L₁(I+1)/10)/10)+1,1)+sub("0123456789",10fPart(L₁(I+1)/10)+1,1)),10)
If " "=sub(Ans,length(Ans),1)
Then
While " "=sub(Ans,length(Ans),1
sub(Ans,1+(" "=sub(Ans,1,1)),length(Ans)-1→Str4
End
Str3+" "+Str4→Str3
DelVar Str4
Else
Str3+" "+Ans→Str3
End
sub(Str0,3+inString(Str0,sub("0123456789",iPart((J+5K)/100)+1,1)+sub("0123456789",10fPart(iPart((J+5K)/10)/10)+1,1)+sub("0123456789",10fPart((J+5K)/10)+1,1)),10)
If " "=sub(Ans,length(Ans),1)
Then
While " "=sub(Ans,length(Ans),1
sub(Ans,1+(" "=sub(Ans,1,1)),length(Ans)-1→Str4
End
Str3+" "+Str4→Str3
DelVar Str4
Else
Str3+" "+Ans→Str3
End
Text(L,0,Str3
L+6→L
End
If I understand correctly, you want to select a string from a set of strings at random and they don't all have the same length... If that's what you want to do, I would suggest something like this:

Code:
"BERSERKERKNIGHTROGUEARCHERMAGEAXESWORD->Str1
{9,6,5,6,4,3,5->L1
augment({1},1+cumSum(L1->L2
dim(L2)-1->dim(L2
randInt(1,dim(L1->A
Disp sub(Str1,L2(A),L1(A

I didn't do all the strings because I'm lazy, but you would just have to add those to the end of Str1, then add the length of each string to L1 (BERSERKER is 9, KNIGHT is 6 and so on) and you should be all set.
  
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 UTC - 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