English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

 
 
Thread Tools
Old 27 March 2017, 02:38   #41
Jackoland
Registered User
 
Join Date: Jun 2014
Location: Leeds
Posts: 174
The most basic of questions!

How do I generate on positive random numbers

I'm doing this at the moment

Rent1=int (rnd(80-150))

But this generates numbers bigger than the range set and negative numbers too.

Cheers
I have been using blitz for about a day. And have the programming knowledge of a nat!

Rich
Jackoland is offline  
Old 27 March 2017, 07:31   #42
tolkien
AmigaMan
 
tolkien's Avatar
 
Join Date: Oct 2012
Location: Castro Urdiales/Spain
Posts: 760
Rent1 = rnd(70)+80

Rnd(70) cos the difference between 80 and 150.
Rnd will generate numbers between 0 and 70 so sum 80 for the offset.
tolkien is offline  
Old 27 March 2017, 07:37   #43
MickGyver
Registered User
 
MickGyver's Avatar
 
Join Date: Oct 2008
Location: Finland
Posts: 643
Quote:
Originally Posted by Jackoland View Post
The most basic of questions!

How do I generate on positive random numbers

I'm doing this at the moment

Rent1=int (rnd(80-150))

But this generates numbers bigger than the range set and negative numbers too.

Cheers
I have been using blitz for about a day. And have the programming knowledge of a nat!

Rich
Here are two examples:

Generate a number between 0 and 150:
Rent1.w = Rnd(150)

Generate a number between 80 and 150
Rent1.w = Rnd(70)+80

Keep at it, Blitz Basic is fun!

EDIT: Tolkien answered this while I was writing...
MickGyver is offline  
Old 27 March 2017, 09:44   #44
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,335
Quote:
Originally Posted by Jackoland View Post
I'm doing this at the moment

Rent1=int (rnd(80-150))
The others have already answered this, I hope it makes sense. I'd just like to add that you don't need the Int() function in Blitz - the Rnd() function automatically returns an integer when the range is greater than 1. Some other BASICs do need it, but it looks neater without it
Daedalus is offline  
Old 27 March 2017, 10:54   #45
Coagulus
Gets there in the end...
 
Coagulus's Avatar
 
Join Date: Sep 2005
Location: Wales
Posts: 862
To clarify, in Blitz, 80-150 means 80 MINUS 150 not 80 TO 150 like you would write in reality.
Coagulus is offline  
Old 27 March 2017, 11:57   #46
Jackoland
Registered User
 
Join Date: Jun 2014
Location: Leeds
Posts: 174
That's great folks! Thanks for the help. I'm really glad of this thread. I don't feel bad asking dumb questions. I'm having a go at a basic shop simulator game. Things like buying, rent, profits and reputation variables.

If I can get a system running, I then want to add in a graphical interface!

Slowly learning, expect more questions!

Cheers rich
Jackoland is offline  
Old 27 March 2017, 12:14   #47
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,335
The only dumb questions are the ones you don't ask Okay, maybe there are some dumb questions, but feel free to ask for help here any time, there are plenty of people around who should be able to help.

The built-in Blitz help is pretty good, and the Blitz section of AmigaCoding.com has a lot of useful reference material too.
Daedalus is offline  
Old 28 March 2017, 23:34   #48
Jackoland
Registered User
 
Join Date: Jun 2014
Location: Leeds
Posts: 174
Hi there. Well I have managed to write some code from a little pseudo code I made. It works so far to the end. Here is the pseudo code.

Shop simulator

;Setup initial variables

Money= random between 500 - 1000 ;final figures to be finalised
Finalrent= 0
Reputation=0
Luck=0
Shop=0
Rent1= random between 50-100
Rent2= random between 120-170
Rent3=random between 150-220 ;final ranges to be confirmed
Username$



;introduction
Print "welcome to shop simulator, what is your name?"
Store input in username
Print "the bank will lend you" , money

Which shop would you like to buy?
1. Holds one product and costs (rent1) per month
2. Holds three products and costs (rent2) per month
3. Holds five products and costs (rent3) per month
Store input in shop variable (use edit command)

If shop equals 1 put rent1 into finalrent
If shop equals 2 put rent2 into finalrent
If shop equals 3 put rent3 into finalrent

Print "you chose shop (shop) and will pay £ (finalrent) per month"

Shopname =
What do you want to call your shop?
Store name in shopname

Print "welcome to (shopname) your shop is now open"

The help I need now is I need lots of products to choose from, it will have a name, cost, year and also the amount it will increase the shops reputation. Would I be best using an array to store these variables?

Then I need to create a loop that
Adds 1 to the day
Checks if it's less than 365
If more then add to year and reset day
Minus rent
Check if money is greater than 0 if not game over
Give opinion to buy from the array variables
Add that to a shop inventory and minus cost from money
Add reputation from product array variable
Check reputation score then add to a customer numbers
Check customers and add money made to money
Check luck
Random luck
If luck high give good news variable - need to create another array for good luck things such as tax return, rent cut etc
If luck low give bad news variable e.g. Flood in store, increase rent, electric bill.


You get the idea. I'm still working out how I would do this, and how to loop it.

Cheers
Rich

Ps think I would be better on new thread
Jackoland is offline  
Old 29 March 2017, 08:27   #49
tolkien
AmigaMan
 
tolkien's Avatar
 
Join Date: Oct 2012
Location: Castro Urdiales/Spain
Posts: 760
I like this thread as Im learning blitz basic but I think we should write each question in differents threads to can search it more easy in the future.
tolkien is offline  
Old 29 March 2017, 09:48   #50
MickGyver
Registered User
 
MickGyver's Avatar
 
Join Date: Oct 2008
Location: Finland
Posts: 643
Quote:
Originally Posted by Jackoland View Post
The help I need now is I need lots of products to choose from, it will have a name, cost, year and also the amount it will increase the shops reputation. Would I be best using an array to store these variables?
You should make a NewType (similar to a C struct) that includes the data for the products. Then you can create an array of that NewType. Like this:

Code:
; Create a NewType for products
NEWTYPE .Product
  name$
  cost.w
  year.w
End NEWTYPE

; Create an array named "Products" containing 200 ".Product" NewType objects (actually 201)
Dim Products.Product(200)
Quote:
Originally Posted by tolkien View Post
I like this thread as Im learning blitz basic but I think we should write each question in differents threads to can search it more easy in the future.
I was thinking the same thing yesterday, it's probably for the best to have separate threads for separate questions.

Last edited by MickGyver; 29 March 2017 at 11:10.
MickGyver is offline  
Old 29 March 2017, 09:57   #51
Twiggy
\m/
 
Twiggy's Avatar
 
Join Date: Nov 2008
Location: Devon, U.K.
Posts: 573
Quote:
Originally Posted by tolkien View Post
I like this thread as Im learning blitz basic but I think we should write each question in differents threads to can search it more easy in the future.
Unless we rename this thread "Blitz Basic questions you've always been too embarrassed to ask"
Twiggy is offline  
Old 29 March 2017, 16:12   #52
Jackoland
Registered User
 
Join Date: Jun 2014
Location: Leeds
Posts: 174
Where am I best declaring the new type? At the beginning in a setup variables procedure?

Cheers
Jackoland is offline  
Old 29 March 2017, 16:46   #53
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,335
You're best off declaring it at the start of your code - it must be before you intend to use it for the first time. I normally have an area near the start of my code where I declare all the arrays, variables, constants and default values I use later on.

If you intend to use it in more than one area of your code, you shouldn't declare it in a procedure, as then it would only be local to that procedure.
Daedalus is offline  
Old 29 March 2017, 23:17   #54
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 4,332
I like to declare them in a separate file and XINCLUDE it at the top of the main file.

It makes the main file less cluttered.
idrougge is offline  
Old 29 March 2017, 23:44   #55
tolkien
AmigaMan
 
tolkien's Avatar
 
Join Date: Oct 2012
Location: Castro Urdiales/Spain
Posts: 760
Nice idea. I'm trying to do all my code more modular.
tolkien is offline  
Old 27 April 2017, 08:17   #56
Havie
Registered User
 
Havie's Avatar
 
Join Date: Mar 2012
Location: UK
Posts: 1,893
Can someone help me with palettes please!

I am using the new Display library commands and Use Palette doesn't work - I keep getting an error that there is no object. So - I have realised that I can't use old commands with the new display list but I have no idea how to get a palette from a shape. I have tried loading with shape with the optional palette command at the end but whatever I do I can't seem to change to this palette. Help!!!
Havie is online now  
Old 27 April 2017, 09:51   #57
MickGyver
Registered User
 
MickGyver's Avatar
 
Join Date: Oct 2008
Location: Finland
Posts: 643
Quote:
Originally Posted by Havie View Post
Can someone help me with palettes please!

I am using the new Display library commands and Use Palette doesn't work - I keep getting an error that there is no object. So - I have realised that I can't use old commands with the new display list but I have no idea how to get a palette from a shape. I have tried loading with shape with the optional palette command at the end but whatever I do I can't seem to change to this palette. Help!!!
Hmm, I haven't used BB2 very much but what has been working for me is to load the palette from the image (containing shapes) with

Code:
LoadPalette 0,"image.iff"
and then after creating the copperlist use DisplayPalette instead of Use Palette

Code:
; DisplayPalette #coplist, #palette
DisplayPalette 0,0
MickGyver is offline  
Old 27 April 2017, 22:54   #58
Havie
Registered User
 
Havie's Avatar
 
Join Date: Mar 2012
Location: UK
Posts: 1,893
Thanks - will have a go and let you know!
Havie is online now  
Old 28 April 2017, 22:32   #59
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,335
That should also work with a palette loaded optionally with the LoadShape command. The Use Palette command is only for screens and slices from what I remember, and was replaced with ShowPalette anyway, which would explain why it doesn't work. DisplayPalette is the equivalent for the Display library so that should work fine.
Daedalus is offline  
Old 28 April 2017, 23:16   #60
Havie
Registered User
 
Havie's Avatar
 
Join Date: Mar 2012
Location: UK
Posts: 1,893
Still struggling - I think I need to sort out the number of bitplanes in the original shapes! Just trying to have black and white and thought I could do this with 1 bit plane. Then think I need 2 bit planes if I want to convert shape to sprite. The thinking that maybe I haven't set up screen properly. I think I will grab some code from a working game and start again...
Havie is online now  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
[blitz basic] How much amiga-blitz friendly is this? saimon69 Coders. Blitz Basic 105 21 April 2022 19:45
Blitz Basic (1) Retro1234 Coders. Blitz Basic 9 18 February 2016 17:54
Blitz basic 2 Help Havie Coders. Blitz Basic 30 08 September 2013 09:15
Blitz Basic 2 anyone? jobro request.Apps 12 28 November 2005 18:15
Blitz Basic 2 LaundroMat Retrogaming General Discussion 5 24 July 2001 08:10

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 08:13.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.14323 seconds with 14 queries