Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,633 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Random Number Generation and basic script structure #320057
04/19/10 15:02
04/19/10 15:02
Joined: Apr 2010
Posts: 20
I
Icarni Offline OP
Newbie
Icarni  Offline OP
Newbie
I

Joined: Apr 2010
Posts: 20
Hey All,

I have really two questions. My first one is regarding random numbers. I want to generate a number between 1 and 256. The code I've written is: integer(random(256)); If I'm reading manual correctly, that's going to give me a number between 0.001...and 256. How can I ensure that my random number will be between 1 and 256?

My second question is regarding structure. Right now I'm writing like this:

Includes
//
bitmaps and variables
//
Panels
//
Functions
//
Function Main

This seems to be working for me, my question is whether or not this type of structure is necessary, or can I move things around a bit?

Thanks for putting up with a newbie!

Re: Random Number Generation and basic script structure [Re: Icarni] #320061
04/19/10 15:10
04/19/10 15:10
Joined: Aug 2003
Posts: 7,440
Red Dwarf
Michael_Schwarz Offline
Senior Expert
Michael_Schwarz  Offline
Senior Expert

Joined: Aug 2003
Posts: 7,440
Red Dwarf
integer(random(256)); will give you a number from 0 to 256, random(256); will give you a number from 0.001 to 256.000

the structure you use if up to you and how you can work with best, the only thing you have to be careful of is that things are DEFINED BEFORE THEY ARE USED.

for example:

function add(i)
{
a = a+i;
}

var a = 0;

is bad

var a = 0;

function add(i)
{
a = a+i;
}

is good


"Sometimes JCL reminds me of Notch, but more competent" ~ Kiyaku
Re: Random Number Generation and basic script structure [Re: Icarni] #320063
04/19/10 15:11
04/19/10 15:11
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Firstly, re-check the manual a bit.
random(256); will give you a number between 0.000000 and 255.999999
integer(random(256)); will give you a random integer between 0 and 255
so you want
integer(random(256)+1); to get a random integer between 1 and 256.
or
clamp(random(256)+1,1,256); to get a random number between 1.000000 and 256.000000.

Secondly, dont change things around, it is FAR more trouble than it is worth.



"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Random Number Generation and basic script structure [Re: EvilSOB] #320065
04/19/10 15:15
04/19/10 15:15
Joined: Apr 2010
Posts: 20
I
Icarni Offline OP
Newbie
Icarni  Offline OP
Newbie
I

Joined: Apr 2010
Posts: 20
Awesome!

Thanks for the advice!

Re: Random Number Generation and basic script structure [Re: Icarni] #320074
04/19/10 16:20
04/19/10 16:20
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
no probs dude... and welcome aboard.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1