Name: Slots

I have bee working on this for quite some time, running into various issues along the way. I have it pretty much complete, but I have a couple of problems.

1) When exiting the app, I have it save the amount of "money" that the player has. however, my method is not the best method. I currently have it adding a digit to a string for each "dollar" and then saving it to an appvar. This is fine when saving small numbers, but can get very tedious when trying to save large numbers. I feel like there is a much easier way to do this. Here is the code that I am currently using.

Code:
If K=22 or K=45
Then
"rowSwap(MONEY"→Str0
det(4)
" "→Str8
For(Y,2,X)
Output(10,26,"0"
Str8+" "→Str8
iPart(Y/X*100→A
Output(7,13,A)
Output(10,26," "
End
Str8→Str9
1
det(1)
Stop
End


In the future, I plan on making a third version (the first was purely BASIC) that will use sprites and the half resolution mode for better graphics and overall experience.[/code]
Okay, you don't need to put all those ending parentheses and quotation marks (except in one obscure case which is not what you have here so you're fine). Just a little tip to keep size down even though it probably doesn't matter since most programs don't exceed the mem available...
As for the money thing, from what I understand, you are using a unary numeral system, which as you said, is heavily inefficient. If this is the case, then you could just store the number in base 10 in the string, and then retrieve the number by reading the string from the appvar and using the expr() token on it. All you need to do is convert that number to a string. Since you are using celtic, I'm assuming you're not doing this for the CE and therefore, you can't use eval() and toString(). Actually, since you use det(1) to store to a string, you are using a CSE, which reminds me, this is a little ironic because det(1) used to be numtostring in DCS7's celtic version, but whatever, you will need to either use an asm subprogram (not recommended since you only do it once) or use the tedious method. You might have seen this around, but there is a way to convert a real variable to a string in pure BASIC (which can then be stored in an appvar) You can read all about it in this article. Basically, just use the routine on there but replace N with the variable holding the amount of money, and Str1 with Str8 in your case, and then you will be able to just store that to your string. It will be exactly one bazillion times faster and take less space for integers larger than 1 Razz

The code to store it to the appvar (and create the appvar) would be something like :

Code:
"rowSwap(MONEY→Str0
det(4
{0,1→L₁
{0,X→L₂
LinReg(ax+b) Y₁
Equ►String(Y₁,Str8
sub(Str8,1,length(Str8)-3→Str9
1:det(1

And the code to read the number from the appvar and store it in X would be something like :

Code:
"rowSwap(MONEY→Str0
1:det(0
expr(Str9→X
I put that into my program, replacing the old code, but now I am getting a syntax error that points to the first line of code, I encountered this despite removing the Doors header.
Often times for me, when there is an error in the code run from Doors, it it displays the top of the code rather than finding the actual code. Don't know why this is, but I don't think its the header.
Kydapoot wrote:
Often times for me, when there is an error in the code run from Doors, it it displays the top of the code rather than finding the actual code. Don't know why this is, but I don't think its the header.

^This. Try temporarily disabling doors and run it from homescreen.
BigSmoke3320 wrote:
I put that into my program, replacing the old code, but now I am getting a syntax error that points to the first line of code, I encountered this despite removing the Doors header.

It works fine for me, would you mind posting the code to see if the context might be befuddling it?
I have solved the problem. upon removing the expr( token, the code began to execute without any problems. here is the revised code anyway:

Code:

DelVar K
0→W
real(0,3,4,0,0)
real(9)
real(0,3,4,0,0)
real(9)
"rowSwap(MONEY"→Str0
1
det(0)
expr(Str9→X //<- removed expr( here
If X≤1
10→X
If X=9
Then
ClrHome
Disp "ERROR OCCURED DURING","PROGRAM EXECUTION.","ERROR CODE:",Str9
10→X
Disp "ATTEMPTING RECOVERY"
"rowSwap(MONEY"→Str0
det(4)
" "→Str8
For(Y,2,X)  // I didn't feel like making that change here, it didn't take long here for this method, and it worked.
Output(10,26,"0"
Str8+" "→Str8
iPart(Y/X*100→A
Output(7,13,A)
Output(10,26," "
End
Str8→Str9
1
det(1)
Stop
End
det(12,31,0,31,0)
Output(4,6,"                 "
Output(5,6," "
Output(5,10," "
Output(5,14," "
Output(5,18," "
Output(5,22," "
Output(6,6,"                 "
det(12,0,4,0,0)
1→W
Repeat 1≠1
0→K
Output(1,1,"                          ")
Repeat K=105 or K=26
Output(10,26,"0")
getKey→K
If K=22 or K=45 or X≤0
Then
"rowSwap(MONEY→Str0
det(4
If X≤0
X+10→X
{0,1→L₁
{0,X→L₂
LinReg(ax+b) Y₁
EquString(Y₁,Str8
sub(Str8,1,length(Str8)-3→Str9
1
det(1
Stop
End
If K=25 and X-W-1≥0
Then
Output(2,1,"      "
W+1→W
End
Output(10,26," "
If K=34 and W>1
Then
Output(2,1,"      "
W-1→W
End
Output(1,1,X)
Output(2,1,W)
End
Output(10,26,"0"
randInt(1,7)→A
randInt(1,7)→B
randInt(1,7)→C
randInt(1,7)→D
Output(10,26," "
Output(10,26,"0"
Output(5,8,A)
Output(5,12,B)
Output(5,16,C)
Output(5,20,D)
Output(10,26," "
X-W→X
Output(10,26,"0"
If A=B
X+W→X
If B=C
X+W→X
If C=D
X+W→X
If A=B and B=C
X+2W→X
If B=C and C=D
X+2W→X
If A=D
X+W→X
If A=C
X+W→X
If B=D
X+W→X
If A=B and B=C and C=D
X+1000W→X
Output(10,26," "
End


Sorry for the lack of optimization, I'm still working on that.
I've tried running your program, but from what I can see, your code will require the MONEY appvar to exist for it to run correctly.
You should change that, so that if it doesn't exist, your program creates it. Luckily, Celtic will place an error code in Str9 if the appvar does not exist (something like "..P:NT:FN", but you should check the SDK to make sure)
So all you have to do is run a command like det(0) which reads the line number in Ans from the appvar\program in Str0, and check if Str9 has been changed to the error code. If it has, then you know it does not exist and you will need to create it. This way, your code won't churn out errors to users who either don't have the appvar or deleted it and it will allow you to only have a single program, which is simpler for users to install (imo)
mr womp womp wrote:
I've tried running your program, but from what I can see, your code will require the MONEY appvar to exist for it to run correctly.
You should change that, so that if it doesn't exist, your program creates it. Luckily, Celtic will place an error code in Str9 if the appvar does not exist (something like "..P:NT:FN", but you should check the SDK to make sure)
So all you have to do is run a command like det(0) which reads the line number in Ans from the appvar\program in Str0, and check if Str9 has been changed to the error code. If it has, then you know it does not exist and you will need to create it. This way, your code won't churn out errors to users who either don't have the appvar or deleted it and it will allow you to only have a single program, which is simpler for users to install (imo)


I have accounted for that by adding this section of code


Code:

If X=9
Then
ClrHome
Disp "ERROR OCCURED DURING","PROGRAM EXECUTION.","ERROR CODE:",Str9
10→X
Disp "ATTEMPTING RECOVERY"
"rowSwap(MONEY"→Str0
det(4)
" "→Str8
For(Y,2,X)  // I didn't feel like making that change here, it didn't take long here for this method, and it worked.
Output(10,26,"0"
Str8+" "→Str8
iPart(Y/X*100→A
Output(7,13,A)
Output(10,26," "
End
Str8→Str9
1
det(1)
Stop
End


This will create the appvar if it does not exist, and then exit. The user re-executes the code, and the game runs normally.
Now that I have sorted out most of the code for the current version, I have begun to work on making Version 3, which will rely more heavily on the hybrid basic libraries. I have just one question, I want text to be erased after using xlibc DrawString. Is there an argument that I can throw to disable the transparency, or do I need to redraw the background after each 'spin'?
BigSmoke3320 wrote:
Now that I have sorted out most of the code for the current version, I have begun to work on making Version 3, which will rely more heavily on the hybrid basic libraries. I have just one question, I want text to be erased after using xlibc DrawString. Is there an argument that I can throw to disable the transparency, or do I need to redraw the background after each 'spin'?

Nope, you can't disable the transparency, I think the easiest way to get around this is to draw a black square before redrawing each number. Also, this is undoccumented in the SDk, but there is a command to display an integer stored in a variable, without having to convert it to a string, which would take more time. It is real(6,1,X,Y,COLOR,VARIABLE,UPDATELCD)
So you could display them with something like this:

Code:
For(E,1,4
real(7,3,X,Y,0,8
real(6,1,X,Y,4,sum({A,B,C,D}seq(X=E,X,1,4
End

Remember, the X values will need to be modified by E (so that the numbers don't display over eachother on the screen) So the X will be something like "20+18E". Of course, those are just made up numbers, but the 20 is the X coordinate of the first number, and the 18 is the distance between two numbers, so you can modify those to fit your needs.
Thank you so much! I didn't know about that, and it helps so much.
that tip reduced my code by 400 kb. (I dont like using subroutines)
The beta version of slots V3 is complete. I have posted the code, but unfortunately I can post the actual file here.


Code:

"rowSwap(TEST→Str0
2
det(0
Str9→X
1→W

real(0,1,1)
"TEST
real(5,2,1)
real(5,2,0)
real(6,1,110,25,0,X,0)
real(9

While 1=1
Repeat K=105 or K=26
getKey→K
If K=45 or X≤0
Then
If X≤0
X+100→X
{0,1}→L₁
{0,X}→L₂
LinReg(ax+b) Y₁
EquString(Y₁,Str9
sub(Str9,1,length(Str9)-3→Str9
Str9→Str5
"rowSwap(TEST→Str0
2
det(1)
If Str9≠Str5
Then
real(0,1,0,1)
ClrHome
Disp Str9
End
{0,W→L₂
LinReg(ax+b) Y₁
EquString(Y₁,Str9
sub(Str9,1,length(Str9)-3→Str9
3
det(1
Stop
End
If K=25 or K=34
Then
If K=25 and X-W≥0
W+1→W
If K=34 and W-1≥1
W-1→W
"TEST
real(5,2,0)
real(6,1,110,25,0,X,0)
real(6,1,110,44,0,W,0)
real(9
End
End
X-W→X

randInt(1,7,4)→L₁
L₁(1)→A
L₁(2)→B
L₁(3)→C
L₁(4)→D

If A=B
X+W→X
If B=C
X+W→X
If C=D
X+W→X
If A=B and A=C
X+2W→X
If B=C and C=D
X+2W→X
If A=B and C=D and B=C
X+10W→X

"TEST
real(5,2,0)
real(6,1,110,25,0,X,0)
real(6,1,110,44,0,W,0)
real(9

"TEST
real(5,2,0)

real(6,1,8,24,50A,A,0
real(6,1,24,24,50B,B,0
real(6,1,40,24,50C,C,0
real(6,1,56,24,50D,D,0
real(6,1,110,25,0,X,0)
real(6,1,110,44,0,W,0)
real(9

End


Optimization, and a few UI changes, and the final version should be released. This should take only about 2 weeks, so if any of you are looking forward to the release, its coming soon.
  
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