GLBasic forum

Main forum => Bug Reports => Topic started by: Yommy on 2010-Jun-25

Title: RND allways outputs 1
Post by: Yommy on 2010-Jun-25
Code (glbasic) Select

// --------------------------------- //
// Project: rnd
// Start: Friday, June 25, 2010
// IDE Version: 8.006

GLOBAL Tile = RND(500)
PRINT Tile,1,1
SHOWSCREEN
KEYWAIT


i have tried with various SEEDRND options, and still allways 1 :(
please can you look into this for me

Yommy <3
Title: Re: RND allways outputs 1
Post by: Marmor on 2010-Jun-25
GLOBAL Tile
Tile = RND(500)
PRINT Tile,1,1
SHOWSCREEN
KEYWAIT
Title: Re: RND allways outputs 1
Post by: Moru on 2010-Jun-25
Yes, the key is to never give the output of a function to a declaration. It has to be on separate lines.

GLOBAL Tile
Tile = RND()...

Title: Re: RND allways outputs 1
Post by: Yommy on 2010-Jun-25
wow, something so simple had me stumped  =D

thanks guys
Yom <3
Title: Re: RND allways outputs 1
Post by: doimus on 2010-Jun-25
Apparently, you haven't read the GLBasic Club Rules.

Rule no1: There is no GLB Club.

Rule no2:. You never talk about GLB club.

Rule no3: You never assign value to a global variable on initialization (although help file says you can in several places).

=D =D =D
Somewhere on this forum there's mine thread asking the same thing and there are several others as well.
Title: Re: RND allways outputs 1
Post by: MrTAToad on 2010-Jun-25
You can with RGB - thats the only one you can...
Title: Re: RND allways outputs 1
Post by: Moru on 2010-Jun-26
Make your life easier in the future, Never initialize a variable with the output from a function (unless it's RGB(), but I would be careful with that too).

GLOBAL x = 5 // Is fine
GLOBAL y = my_function() // Is not fine (except on every 5:th patch of GLBasic and only during full-moon :-)
GLOBAL z = RGB() // Should work but I try not to do it.

FUNCTION my_function: color = RGB() // should also work
FUNCTION my_function: string$ = MID$("HELLO", 2, 1) // won't work and probably gives funny error messages that you will spend hours trying to find :-)

Disclaimer: Code written after being away from GLBasic for a while, might contain errors... :-)