Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Random function problem... in a function

Author
Message
Djbios76
8
Years of Service
User Offline
Joined: 5th Mar 2016
Location:
Posted: 5th Mar 2016 12:50
Hi guys,

I?ve a problem. If I put "Random(x, y)" in a main do/loop cycle it works fine. But if I put it in a function, and I call the function inside the do/loop, it doesn't work. Is it a common problem or just mine? Tested on Windows and Android.


Thanks so much for the support!

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 5th Mar 2016 13:28 Edited at: 5th Mar 2016 13:29
You'd need to post some code to diagnose the issue fully.
But my guess is, you are using a variable that you haven't declared as global. Therefore, teh function makes its own local version of that variable name.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 5th Mar 2016 15:43
Variables x and y will be 0 inside your function if you haven't declared them as global or set their value inside your function. Each function use a separate set of variables than the rest of your code. This is called variable scope. All variables are by default local and is separate for your main code and each function. By declaring a variable as global it will retain its value both inside and outside of functions.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 5th Mar 2016 17:02
try at top of main this
#option_explicit
AGK (Steam) V2.0.17 : Windows 10 Pro 64 Bit : AMD (15.30.1025) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 7th Mar 2016 08:25
Quote: "If I put "Random(x, y)" in a main do/loop cycle it works fine. But if I put it in a function, and I call the function inside the do/loop, it doesn't work."


I'd also guess that you haven't declared x and y as global variable, but without any sample code, or reply from you to confirm, it is hard to say for sure.

V2 T1 (Mostly)
Phone Tap!
Uzmadesign

Login to post a reply

Server time is: 2024-09-29 11:31:20
Your offset time is: 2024-09-29 11:31:20