![]() |
![]() |
#41 |
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 |
![]() |
![]() |
#42 |
AmigaMan
Join Date: Oct 2012
Location: Castro Urdiales/Spain
Posts: 766
|
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. |
![]() |
![]() |
#43 | |
Registered User
Join Date: Oct 2008
Location: Finland
Posts: 643
|
Quote:
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... ![]() |
|
![]() |
![]() |
#44 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,416
|
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
![]() |
![]() |
![]() |
#45 |
Gets there in the end...
Join Date: Sep 2005
Location: Wales
Posts: 880
|
To clarify, in Blitz, 80-150 means 80 MINUS 150 not 80 TO 150 like you would write in reality.
|
![]() |
![]() |
#46 |
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 |
![]() |
![]() |
#47 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,416
|
The only dumb questions are the ones you don't ask
![]() The built-in Blitz help is pretty good, and the Blitz section of AmigaCoding.com has a lot of useful reference material too. |
![]() |
![]() |
#48 |
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 |
![]() |
![]() |
#49 |
AmigaMan
Join Date: Oct 2012
Location: Castro Urdiales/Spain
Posts: 766
|
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.
|
![]() |
![]() |
#50 | |
Registered User
Join Date: Oct 2008
Location: Finland
Posts: 643
|
Quote:
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) Last edited by MickGyver; 29 March 2017 at 11:10. |
|
![]() |
![]() |
#51 |
\m/
Join Date: Nov 2008
Location: Devon, U.K.
Posts: 577
|
|
![]() |
![]() |
#52 |
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 |
![]() |
![]() |
#53 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,416
|
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. |
![]() |
![]() |
#54 |
Registered User
Join Date: Sep 2007
Location: Stockholm
Posts: 4,377
|
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. |
![]() |
![]() |
#55 |
AmigaMan
Join Date: Oct 2012
Location: Castro Urdiales/Spain
Posts: 766
|
Nice idea. I'm trying to do all my code more modular.
|
![]() |
![]() |
#56 |
Registered User
Join Date: Mar 2012
Location: UK
Posts: 1,908
|
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!!! |
![]() |
![]() |
#57 | |
Registered User
Join Date: Oct 2008
Location: Finland
Posts: 643
|
Quote:
Code:
LoadPalette 0,"image.iff" Code:
; DisplayPalette #coplist, #palette DisplayPalette 0,0 |
|
![]() |
![]() |
#58 |
Registered User
Join Date: Mar 2012
Location: UK
Posts: 1,908
|
Thanks - will have a go and let you know!
|
![]() |
![]() |
#59 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,416
|
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.
|
![]() |
![]() |
#60 |
Registered User
Join Date: Mar 2012
Location: UK
Posts: 1,908
|
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...
|
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
![]() |
||||
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 |
|
|