So I am developing a large game where you are in charge of a toy store, and you can buy toys and whatnot. Now I am trying to create something where when I go to start the day, the program would first have a max amount of customers and then a random amount of customers between 1 and max, A. This is all working fine. The part i'm having troubles with is when I go to randomize how much stock is sold. So say I have 15 Plastic Toy, and 5 Lego Sets. So I should be able to sell a random number between 0 and 15 for the Plastic Toys, but I have a max amount of customers who can buy toys, only 1 per. So say my max amount of customers was 10, I randomized it and got 5. Then say I randomized Plastic Toys, and I got 13. I can't do this obviously, because there aren't enough customers. So I need a way to make it random between 0 and Max for the toys, but then a higher MAX of customers.

If anyone knows some code I could use, any help would be appreciated.
Thanks!

This is the part of code:


Code:

D+1->D
"A is the total amount of customers you can have
randInt(1,A)->A
Lbl D1
randInt(0,P)->V
If P>A
Then
    Goto D1
Else
    A-V->A
    P-V->P
    M+(15*V)->M
End
Lbl D2
randInt(0,L)->W
If W>A
Then
    Goto D2
Else
    A-W->A
    L-W->L
    M+(45*W)->M
End
Lbl D3
randInt(0,T)->X
If X>A
Then
    Goto D3
Else
    A-X->A
    T-X->T
    M+(103*X)->M
End
Lbl D4
randInt(0,I)->Y
If Y>A
Then
    Goto D4
Else
    A-Y->A
    I-Y->I
    M+(245*Y)->M
End
Lbl D5
randInt(0,S)->Z
If Z>A
Then
    Goto D5
Else
    A-Z->A
    S-Z->S
    M+(600*Z)->M
End

Text(~1,1,1,"DAY: ",D
Text(11,1,"Total Customers: ",A

Text(18,1,"Plast Toys Sold: ",V
Text(25,1,"Lego Sets Sold: ",W
Text(32,1,"Metal Toys Sold: ",X
Text(39,1,"Bicycles Sold: ",Y
Text(46,1,"Swings Sold: ",Z

A little problem with this.
L,T,I,Y,Z are unspecified before used so they will equal 0 Before being set

I don't know exactly what you want so please specify it a little more. And don't worry, I am working on the code optimizing and other things.
FIXED! I worked on the code figured out what you want and, fixed the code.
The values tie together with the code you had before...

Code:

{D,A,V,W,X,I,S}->L1
L1(2)->A
{0,0,0,0,0}->L2
For(W,3,7
   Repeat L2(W-2)<=A
      randInt(0,L1(W))->L2(W-2)
   End
   L1(W)-L2(W-2)->L1(W)
   A-L2(W-2)->A
End
AxesOff
ClrDraw
Text(~1,1,1,"DAY: ",D
Text(11,1,"Total Customers: ",L1(2)

Text(18,1,"Plast Toys Sold: ",L2(1)
Text(25,1,"Lego Sets Sold: ",L2(2)
Text(32,1,"Metal Toys Sold: ",L2(3)
Text(39,1,"Bicycles Sold: ",L2(4)
Text(46,1,"Swings Sold: ",L2(5)
Thanks so much! I'll test it out later today hopefully and i'll let you know if it works for my program!
So the code seems to work, but it gives a value even if you had none in stock, so it puts the stock at a negative value. I will put the entire program here as that may be easier to figure out what i'm talking about. There is a bunch of unfinished work here, so you can ignore that.

Code:

:"Survivor   Ember
ClrHome
ClrDraw
AxesOff
ClockOn
GridOff
LabelOff
PlotsOff
FnOff
ExprOff
CoordOn
1->Xmin
95->Xmax
1->Ymin
63->Ymax
Goto 2


Lbl AB
Menu("Reset Everything?","Yes",AC,"No",A7
Lbl AC
ClrDraw
ClrHome
DelVar ADelVar BDelVar CDelVar DDelVar EDelVar FDelVar GDelVar HDelVar IDelVar JDelVar KDelVar LDelVar MDelVar NDelVar ODelVar PDelVar QDelVar RDelVar SDelVar TDelVar UDelVar VDelVar WDelVar XDelVar YDelVar Z
50->M
1->P
10->A

Lbl 2
ClrDraw
Text(1,1,"Survivor : Ember   |v1.7
Horizontal 55
Text(9,1,"1. Play
Text(16,1,"2. Help
Text(23,1,"3. Load
Text(30,1,"4. Quit
Repeat K=92 or K=93 or K=94 or K=82
   getKey->K
End
If K=91
Then
   ClrDraw
   Text(0,0,"Welcome To Ember! This guide will help you get started. To begin, choose
   Pause
   Goto 2
End
If K=92
Then
   Goto 3
End
Lbl 3
ClrDraw

Text(1,15,"The City of Caraway
Horizontal 55
Text(51,3,"Casino
Text(57,9,"(1)
Text(51,27,"Invest
Text(57,33,"(2)
Text(51,52,"Village
Text(57,59,"(3)
Text(15,3,"Back
Text(22,3,"(Del)
Repeat K=92 or K=93 or K=94
   getKey->K
End
If K=92
Then
   Goto 4
End
If K=93
Then
   Goto 5
   If K=94
   Then Goto 6
   End
End
"Village
Lbl 6
Output(5,4,"Loading..."
dim(rand(100

Lbl A7
Menu("----Toy Store---c-","*START DAY*",A1,"Buy Stock",A2,"Check Stock",A3,"Hire",A4,"Options",A5,"*BACK*",A6

Lbl A1
"Start Day
ClrDraw
ClrHome
If M<~500
Then
   Output(5,4,"Bankrupt!
   Pause
   Goto AC
End
"This is where I put your code
D+1->D
{D,A,V,W,X,I,S}->L1
L1(2)->A
{0,0,0,0,0}->L2
For(W,3,7
   Repeat L2(W-2)<=A
      randInt(0,L1(W))->L2(W-2)
   End
   L1(W)-L2(W-2)->L1(W)
   A-L2(W-2)->A
End
AxesOff
ClrDraw
Text(~1,1,1,"DAY: ",D
Text(11,1,"Total Customers: ",L1(2)


Text(18,1,"Plast Toys Sold: ",L2(1)
P-L2(1)->P
Text(25,1,"Lego Sets Sold: ",L2(2)
L-L2(2)->L
Text(32,1,"Metal Toys Sold: ",L2(3)
T-L2(3)->T
Text(39,1,"Bicycles Sold: ",L2(4)
I-L2(4)->I
Text(46,1,"Swings Sold: ",L2(5)
S-L2(5)->S






Pause
ClrHome
ClrDraw
If M<=30
Goto 9
Lbl 5
randInt(1,5+(G*5))->B
If B=5
Then
   randInt(1,M)->B
   M-B->M
   ClrHome
   ClrDraw
   Output(4,1,"You Got Robbed!
   Output(5,1,"You Lost: $"
   Output(5,12,B
   Pause
   
   
End
Lbl 9
ClrHome
ClrDraw
Output(4,3,"Cash: $"
Output(4,10,M
Pause
Goto A7
























Lbl A6
Goto 3
Lbl A5
Menu("Options","**RESET**",AB,"*BACK*",A7

Lbl A2
Menu("Buy Stock","Plastic Toys",B1,"Lego Sets",B2,"Metal Toys",B3,"Bicycles",B4,"Swings",B5,"*BACK*",A7

Lbl B1
ClrHome
ClrDraw

Disp "Plastic Toys
Disp "Owned:
Disp "Cost: $10"
Disp "Can Afford: "
Output(2,7,P
Output(4,12,int(M/10
Input "Buy:",H
If (10*H)>M
Then
   ClrDraw
   ClrHome
   Disp "Not Enough Cash!"
   Pause
   Goto B1
   
Else
   (M-(10*H))->M
   P+H->P
End
ClrDraw
ClrHome
Output(5,4,"Purchased!
Pause
Goto A7


Lbl B2
ClrHome
ClrDraw
Disp "Lego Sets
Disp "Owned:
Disp "Cost: $30"
Disp "Can Afford: "
Output(2,7,L
Output(4,12,int(M/30
Input "Buy:",H
If (30*H)>M
Then
   ClrDraw
   ClrHome
   Disp "Not Enough Cash!"
   Pause
   Goto B2
   
Else
   (M-(30*H))->M
   L+H->L
End
ClrDraw
ClrHome
Output(5,4,"Purchased!
Pause
Goto A7


Lbl B3
ClrHome
ClrDraw
Disp "Metal Toys
Disp "Owned:
Disp "Cost: $75"
Disp "Can Afford: "
Output(2,7,T
Output(4,12,int(M/75
Input "Buy:",H
If (75*H)>M
Then
   ClrDraw
   ClrHome
   Disp "Not Enough Cash!"
   Pause
   Goto B3
   
Else
   (M-(75*H))->M
   T+H->T
End
ClrDraw
ClrHome
Output(5,4,"Purchased!
Pause
Goto A7

Lbl B4
ClrHome
ClrDraw
Disp "Bicycles
Disp "Owned:
Disp "Cost: $200"
Disp "Can Afford: "
Output(2,7,I
Output(4,12,int(M/200
Input "Buy:",H
If (200*H)>M
Then
   ClrDraw
   ClrHome
   Disp "Not Enough Cash!"
   Pause
   Goto B4
   
Else
   (M-(200*H))->M
   I+H->I
End
ClrDraw
ClrHome
Output(5,4,"Purchased!
Pause
Goto A7

"
Lbl B5
ClrHome
ClrDraw
Disp "Swings
Disp "Owned:
Disp "Cost: $500"
Disp "Can Afford: "
Output(2,7,S
Output(4,12,int(M/500
Input "Buy:",H
If (500*H)>M
Then
   ClrDraw
   ClrHome
   Disp "Not Enough Cash!"
   Pause
   Goto B5
   
Else
   (M-(500*H))->M
   S+H->S
End
ClrDraw
ClrHome
Output(5,4,"Purchased!
Pause
Goto A7
"




Lbl A3
ClrDraw
Text(1,24,"Check Stock"
Horizontal 55

Text(9,1,"Cash: $",M
Text(16,1,"Plas. Toys: ",P
Text(23,1,"Lego Sets: ",L
Text(30,1,"Metal Toys: ",T
Text(37,1,"Bikes: ",I
Text(44,1,"Swings: ",S
Text(9,53,"Clerks: ",C
Text(23,53,"Guards: ",G
Text(16,53,"Restockers: ",R
Text(30,53,"Managers: ",N

Pause
Goto A7
Lbl A4
ClrHome
ClrDraw
Menu("------Hire-----","Clerk     $100",C1,"Restocker $500",C2,"Guard     $700 ",C3,"Manager  $1000",C4,"*BACK*",A7

Lbl C1
If M<100
Then
   Output(4,1,"Not Enough Cash!
   Pause
   Goto A7
End
End
Output(4,1,"     Hired!

C+1->C
M-100->M
Pause
Goto A7

Lbl C2
If M<500
Then
   Output(4,1,"Not Enough Cash!
   Pause
   Goto A7
End
End
Output(4,1,"     Hired!

R+1->R
M-500->M
Pause
Goto A7

Lbl C3
If M<700
Then
   Output(4,1,"Not Enough Cash!
   Pause
   Goto A7
End
End
Output(4,1,"     Hired!

G+1->G
M-700->M
Pause
Goto A7

Lbl C4
If M<1000
Then
   Output(4,1,"Not Enough Cash!
   Pause
   Goto A2
End
End
Output(4,1,"     Hired!

N+1->N
M-1000->M
Pause
Goto A7







Lbl 5
Output(5,4,"Loading..."
dim(rand(100
ClrDraw
Text(1,26,"Stock Market
Horizontal 55
Text(9,1,"1. Materials
Text(16,1,"2. Parts
Text(23,1,"3. Decor
Repeat K=92 or K=93 or K=94
   getKey->K
   If K=92
   Then
      Text(1,60,"M=
   End
End







Pause










Lbl 4
ClrHome
Output(5,4,"Loading...
dim(rand(100
ClrDraw
Text(1,22,"Caraway Casino
Horizontal 55
Line(85,42,73,42
Line(73,41,85,41
Line(72,41,72,22
Line(71,23,71,40
Line(73,22,85,22
Line(85,21,73,21
Line(57,22,69,22
Line(69,21,57,21
Line(56,22,56,41
Line(55,40,55,23
Line(57,42,69,42
Line(69,41,57,41
Text(9,1,"1. Lottery
Text(16,1,"2. Spin The Wheel
Text(23,1,"3. Coin Flip
Text(30,1,"4. Slots
Repeat K=92 or K=93 or K=94 or K=95
   getKey->K
End
If K=94
Then
So a little problem, your code is super unorganized. also instead of using Variables like A B and C. Use a list. Lists are a string of values that are stored in a set place, for instance...

Instead of this...

Code:

1->A
2->B
3->C
4->D
5->E
If <Reset Condition>
Delvar ADelvar BDelvar CDelvar DDelvar E
<rest of game code>


Do this...

Code:

{1,2,3,4,5}->|LSAVE
If <reset Condition>
Fill(0,|LSAVE
<Rest of game code>


This will simplify and also keep the game values like money from getting changed or deleted. Try to use Variables for temporary things like a X and Y Position.
Thanks for the tip!
In order to do it you will have to rewrite large portions of your code. I can help with it though if you want.
Sure that'd be great! I won't be able to work on it until later, but if you can at least help me get started, that'd be awesome!
A Small Question, would you like me to make a large portion of the game? or just set up the menus and let you do the rest? as in I make the main functions, and you make the menus and design it.
You could just do the main functions and I could do the rest. And you mean just replacing all the variables with strings? This is just a hobby and I just do a little bit every now and then, so no need too work to hard on it. I enjoy doing the coding, there are just things i get stuck on, and I'm not that familiar with things like strings. Thanks for the help!
once i get going i never stop, i am going to work hard on this code. you need it.
Thanks so much, but again you don't need to do too much. I have to focus on school, but of course your help is much appreciated
So I Decided That you should work on this code on your own, I am more compelled to make programs that are for things like math and not games. Also you need to grow and learn in this language if you are going to learn and do more in this language. you should do this on your own.
  
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