RND allways outputs 1

Previous topic - Next topic

Yommy

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

Marmor

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

Moru

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()...


Yommy

wow, something so simple had me stumped  =D

thanks guys
Yom <3

doimus

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.

MrTAToad

You can with RGB - thats the only one you can...

Moru

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... :-)