|
Goombert
|
|
Reply #1 Posted on: April 29, 2014, 01:00:52 am |
|
|
Location: Cappuccino, CA Joined: Jan 2013
Posts: 2993
|
Yeah, lol, you don't do int var, you just do int, var means variant meaning it overloads all the other types, a var is technically an int, so what you wrote was int int, which is gibberish.
|
|
|
Logged
|
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.
|
|
|
Darkstar2
|
|
Reply #2 Posted on: April 29, 2014, 01:05:31 am |
|
|
Joined: Jan 2014
Posts: 1238
|
I did that. int a does not work! According to doc the type preceeds the variable example: int a char a bool a etc but in enigma it does not work If I were to do int a a=4.50 show_message(string(a)); it would show 4.50, or sometimes nothing
|
|
|
Logged
|
|
|
|
Goombert
|
|
Reply #3 Posted on: April 29, 2014, 01:17:39 am |
|
|
Location: Cappuccino, CA Joined: Jan 2013
Posts: 2993
|
Actually no, that call would show you 4, because int is not floating point, you want a float for fractional numbers, integers for whole numbers.
In fact, I just put the following in the create event of an object and it built fine, it was most likely erroring because you were implicitly casting a floating point to integer causing loss of precision.
int ass = 5;
Works fine in ENIGMA.
In fact, I just ran your code, and it built fine and showed me the number 4.
int a=4.50; show_message(string(a));
This shows me 4.5, so you're doing something wrong.
float a=4.50; show_message(string(a));
At any rate, it's a good thing for you to learn using these real data types and use them instead of var, because in GM or ENIGMA, it really is horrible, you have no idea how much is going on behind the scenes.
|
|
« Last Edit: April 29, 2014, 01:20:16 am by Robert B Colton »
|
Logged
|
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.
|
|
|
|
Goombert
|
|
Reply #5 Posted on: April 29, 2014, 01:39:23 am |
|
|
Location: Cappuccino, CA Joined: Jan 2013
Posts: 2993
|
Ok, but I'm still pretty sure 4.5 integer would not make sense in any BASIC compiler that I know of, I think you're just remembering wrong.
But yeah, I also tested exactly what you had without me adding a colon, and it still worked fine and showed me the number 4.
int a a=4.50 show_message(string(a));
|
|
|
Logged
|
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.
|
|
|
Darkstar2
|
|
Reply #6 Posted on: April 29, 2014, 01:50:52 am |
|
|
Joined: Jan 2014
Posts: 1238
|
Ok, but I'm still pretty sure 4.5 integer would not make sense in any BASIC compiler that I know of, I think you're just remembering wrong.
But yeah, I also tested exactly what you had without me adding a colon, and it still worked fine and showed me the number 4.
int a a=4.50 show_message(string(a));
and for global a would I do this int global a a=4.50 or int global a global.a=4.50
|
|
|
Logged
|
|
|
|
Goombert
|
|
Reply #7 Posted on: April 29, 2014, 01:55:11 am |
|
|
Location: Cappuccino, CA Joined: Jan 2013
Posts: 2993
|
Oh wow, now that I am not sure, you'd have to ask Josh. It would probably be global int not vice versa.
|
|
|
Logged
|
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.
|
|
|
egofree
|
|
Reply #8 Posted on: April 29, 2014, 02:29:11 am |
|
|
Joined: Jun 2013
Posts: 601
|
I think there is problems with global variables right now. In an empty project, just try to create a script with this line inside : global myvar = 10; I took this simple example from http://enigma-dev.org/docs/Wiki/GlobalYou will have the following error message: In file included from SHELLmain.cpp:102:0: C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h: In function 'variant _SCR_scr_0(variant, variant, variant, variant, variant, variant, variant, variant, variant, variant, variant, variant, variant, variant, variant, variant)': C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h:35:32: error: 'globalmself' was not declared in this scope enigma::varaccess_yvar(int(globalmself))= 10;
If you declare instead global var myvar = 10; You don't have anymore the error message. But if i try to display the value in an object : show_message(string(myvar)); It displays nothing.
|
|
|
Logged
|
|
|
|
Darkstar2
|
|
Reply #9 Posted on: April 29, 2014, 03:00:39 am |
|
|
Joined: Jan 2014
Posts: 1238
|
I think there is problems with global variables right now. In an empty project, just try to create a script with this line inside :
global myvar = 10; I took this simple example from http://enigma-dev.org/docs/Wiki/Global
You will have the following error message:
In file included from SHELLmain.cpp:102:0: C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h: In function 'variant _SCR_scr_0(variant, variant, variant, variant, variant, variant, variant, variant, variant, variant, variant, variant, variant, variant, variant, variant)': C:/ProgramData/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h:35:32: error: 'globalmself' was not declared in this scope enigma::varaccess_yvar(int(globalmself))= 10;
If you declare instead
global var myvar = 10; You don't have anymore the error message. But if i try to display the value in an object :
show_message(string(myvar)); It displays nothing.
It displays nothing because it shouldn't because you are not calling the script, so how is it going to know ? things in scripts don't automatically get executed, they have to be called. In your case you are right if you don't declare type, you get the message error, however, using declared I got it to work with your example. scr_0 (script) global var myvar=10; (you can use var, int, bool, etc.) in this example I would have personally used global int myvar=10, but anyway. obj_0 (create event) scr_0(); (this calls the script, you need to do this ) show_message(string(myvar)); When I run it displays a 10. So it works. If you don't call the script, it won't display anything, that's how scripts are supposed to work In your example you would not even need a script if it's not used, so you would place the global int myvar=10 into your object and not in a script. BTW Robert, I figured out what I was doing wrong, sort of. Seems global do work after all.
|
|
« Last Edit: April 29, 2014, 03:02:43 am by Darkstar2 »
|
Logged
|
|
|
|
Goombert
|
|
Reply #10 Posted on: April 29, 2014, 03:16:22 am |
|
|
Location: Cappuccino, CA Joined: Jan 2013
Posts: 2993
|
var and globalvar are being removed from Studio anyway, all variables used will be declared, that doesn't mean initialized though. http://gmc.yoyogames.com/index.php?showtopic=606791
|
|
|
Logged
|
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.
|
|
|
egofree
|
|
Reply #11 Posted on: April 29, 2014, 03:35:02 am |
|
|
Joined: Jun 2013
Posts: 601
|
I've an object and in the click event, i've written the following code: global var myvar = 10; show_message(string(myvar)); Still, i've an empty message box. Do you know why ? Here is an screenshot:
|
|
|
Logged
|
|
|
|
Goombert
|
|
Reply #12 Posted on: April 29, 2014, 03:42:51 am |
|
|
Location: Cappuccino, CA Joined: Jan 2013
Posts: 2993
|
I do not know the answer to that egofree, I'm sorry, try globalvar instead of global var, no space. Josh can answer these questions, I've sent him a PM to explain it.
|
|
|
Logged
|
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.
|
|
|
|
|
|