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 / Variable Define BUG?

Author
Message
Chmava
10
Years of Service
User Offline
Joined: 20th Jun 2013
Location:
Posted: 21st Aug 2015 12:33 Edited at: 21st Aug 2015 12:35
As attached, how is it this is a bug?!
The Variable has yet to be define!
Perhaps this is a compiler check issue...

Just incase attached image do not work:

Attachments

Login to view attachments
Fluorescent
FPSC Reloaded TGC Backer
18
Years of Service
User Offline
Joined: 1st Aug 2005
Location: Stockholm, Sweden
Posted: 21st Aug 2015 12:57
You define returnvalue inside the ifs and I think the scope is the entire function. So move the definition outside the if and it should work.
Chmava
10
Years of Service
User Offline
Joined: 20th Jun 2013
Location:
Posted: 21st Aug 2015 13:05
That is the thing really... it has yet to be define!
If it is the entire scope, then they need to update their error checker again...
Fluorescent
FPSC Reloaded TGC Backer
18
Years of Service
User Offline
Joined: 1st Aug 2005
Location: Stockholm, Sweden
Posted: 21st Aug 2015 13:29
I'm not sure, but I've alwaysed assumed that AppGameKit behaves like JavaScript where variables in a function is scoped to the entire function regardless of where they where defined.

So because you defined returnValue in one branch of the if, it's available in the other. It may be wrong, but it's my assumption that it works like that.
Chmava
10
Years of Service
User Offline
Joined: 20th Jun 2013
Location:
Posted: 21st Aug 2015 13:43
Well, i need the function to return different type of variable.
The variable should not exists until it is define, regardless of where it is in a function?
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 21st Aug 2015 14:18
correct me if I am wrong (usually am lol), but the AppGameKit compiler is a multi-pass compiler and not a 1 pass, with multi pass the entire script is read into memory this is what is causing the issue you are having as the program needs to know "everything" in your code, with a 1 pass compiler it would have worked as you expected as the compiler would read the code line by line, Lua and many other scripting languages work this way, its just the way it is

some info on the subject
https://en.wikipedia.org/wiki/Multi-pass_compiler
https://en.wikipedia.org/wiki/One-pass_compiler
Chmava
10
Years of Service
User Offline
Joined: 20th Jun 2013
Location:
Posted: 21st Aug 2015 16:22
Well, this was not an issue in tier 2 and language like PHP?
Fluorescent
FPSC Reloaded TGC Backer
18
Years of Service
User Offline
Joined: 1st Aug 2005
Location: Stockholm, Sweden
Posted: 21st Aug 2015 17:36
Quote: "main.agc:25: error: Cannot convert type String to Integer, data type must match the value returned by EndFunction"

I think this means that your function can only return one data type. So you can't return an integer in one if-branch and a string in another.

You have to choose either integer or string.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 21st Aug 2015 19:09
if you want return string and integer u can use a user defined type.
type TMultiResult
mystring as string
myinteger as integer
endtype

AGK (Steam) V2 Beta .. : Windows 10 Pro, 8.1 Pro 64 Bit : AMD (15.7.1) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Chmava
10
Years of Service
User Offline
Joined: 20th Jun 2013
Location:
Posted: 21st Aug 2015 21:18 Edited at: 21st Aug 2015 21:18
.....

Basically what happen is, the script has YET to define what type the variable is!
In other word, the program does not actually see what type it is until it meets the condition.

The function itself dump the variable upon completion, so there is no reason why the defined variable has to be defined only once.
As only variable can be return from a function.

No, i do not wish to return an array from a function.

And yes, i can just hard program it to call without a function...
Guess i will change to that instead...
Yodaman Jer
User Banned
Posted: 22nd Aug 2015 06:08
Perhaps a dumb suggestion, but have you tried naming the variables something else just in case there is a bug regarding that?

Like, you could do returnIntValue and then returnStringValue?


Forum President until June 20th, 2016. Bow down to me!
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 22nd Aug 2015 09:42
Quote: "Basically what happen is, the script has YET to define what type the variable is!"

You shouldn't be trying to do this in a strongly typed language like AppGameKit BASIC (which also isn't OO).

It's also bad practice to declare something inside a conditional and then attempt to use it after the conditional.

I could be wrong on this but I'm pretty sure AppGameKit functions can only return the one data type determined by the variable that you return. Flourescent's quote seems to confirm this.

The best solution in this instance is Markus's.
Chmava
10
Years of Service
User Offline
Joined: 20th Jun 2013
Location:
Posted: 22nd Aug 2015 12:20
No, i could not return the function like this:

EndFunction returnIntValue, returnStringValue

or even like this:

EndFunction (returnIntValue = 1 ? returnIntValue : (returnStringValue = '' ? returnStringValue : false))

and returning an array only create overhead.
Because after i call the function, i need to check if it is a string, integer or float, put it inside another tmp variable, then use it that way.

i could definitely return it as such:

EndFunction value$

Then use:

Val(_functionName(1,1,1))

But as i mention, alot of overhead.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 22nd Aug 2015 12:20
something like this whould give u all properties u need.
the struct is a copy from the array entry.


AGK (Steam) V2 Beta .. : Windows 10 Pro, 8.1 Pro 64 Bit : AMD (15.7.1) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Chmava
10
Years of Service
User Offline
Joined: 20th Jun 2013
Location:
Posted: 22nd Aug 2015 12:28 Edited at: 22nd Aug 2015 12:29
omg, i wish i can loop this like in c++ to give me the ability to get any value from infinite nest array!

Also, when will they have to abilities to save array in file?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 22nd Aug 2015 12:36
that sounds u need a recursive function to find something.

AGK (Steam) V2 Beta .. : Windows 10 Pro, 8.1 Pro 64 Bit : AMD (15.7.1) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Chmava
10
Years of Service
User Offline
Joined: 20th Jun 2013
Location:
Posted: 22nd Aug 2015 12:52
Yes, the array is currently 3 nest deep.

Login to post a reply

Server time is: 2024-04-26 12:01:24
Your offset time is: 2024-04-26 12:01:24