Author Topic: RND allways outputs 1  (Read 1854 times)

Offline Yommy

  • Mc. Print
  • *
  • Posts: 14
    • View Profile
RND allways outputs 1
« 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

Offline Marmor

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 913
  • 96A285CC
    • View Profile
    • my youtube channel
Re: RND allways outputs 1
« Reply #1 on: 2010-Jun-25 »
GLOBAL Tile
Tile = RND(500)
PRINT Tile,1,1
SHOWSCREEN
KEYWAIT

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1783
    • View Profile
    • Homepage
Re: RND allways outputs 1
« Reply #2 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()...


Offline Yommy

  • Mc. Print
  • *
  • Posts: 14
    • View Profile
Re: RND allways outputs 1
« Reply #3 on: 2010-Jun-25 »
wow, something so simple had me stumped  =D

thanks guys
Yom <3

Offline doimus

  • Dr. Type
  • ****
  • Posts: 284
    • View Profile
Re: RND allways outputs 1
« Reply #4 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.

MrTAToad

  • Guest
Re: RND allways outputs 1
« Reply #5 on: 2010-Jun-25 »
You can with RGB - thats the only one you can...

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1783
    • View Profile
    • Homepage
Re: RND allways outputs 1
« Reply #6 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... :-)