About Monkey 2 › Forums › Monkey 2 Programming Help › Import/Includes and globals?
This topic contains 21 replies, has 7 voices, and was last updated by 
 Richard Betson
 2 years, 6 months ago.
- 
		AuthorPosts
 - 
		
			
				
July 25, 2016 at 11:18 am #2427
Having
Monkey1Global MyVar := 1.0in a separate monkey2 file and then using #Import or #Include to add it into the main source file so you can call the variable from numerous different monkey2 files for example I get the error ‘MyVar not found’ its in there and the whole thing compiles to that point. Anyone have any idea how to import globals into another source file as I dont want to have all the source in one file but instead put all Global declarations in a separate file.
July 25, 2016 at 11:37 am #2428Does this not work for you?
globals.monkey2
Global MyVar := 1.0
start.monkey2
[/crayon]Monkey123456[crayon-5cba87fd70069840243775 inline="true" ]#import "globals.monkey2"Function Main:Void()Print MyVarEndJuly 25, 2016 at 11:54 am #2430Nope I get Error : Identifier ‘MyVar’ not found
im currently using the binary v1.0.0
July 25, 2016 at 11:59 am #2431Interesting.
I’m using 1.0.2 (latest git clone zip) and don’t see that error…
July 25, 2016 at 11:59 am #2432Are you using namespaces? Make sure to reference these if you are.
July 25, 2016 at 12:03 pm #2433The example impixi up also fails
July 25, 2016 at 12:25 pm #2436It’s possible something was fixed since v1.0.0 if that code doesn’t work. As Weibow says, either have no namespace at all in each file, or make sure you do have one in each file.
Monkey123Namespace myappGlobal myvar:="Hello World"Monkey12345678Namespace myapp#import "globals.monkey2"Function Main:Void()Print myvarEndJuly 25, 2016 at 3:16 pm #2440peterigz: Tried and still results in a error :/
July 25, 2016 at 5:12 pm #2444@edzup: These examples work here for me, and I’m still on 1.0.1. It even works without declaring a namespace.
You are sure the file’s named correctly, right? Same file extension, too?
July 25, 2016 at 5:14 pm #2445Yeah even made sure the files are in the same directory etc.
July 25, 2016 at 5:48 pm #2448I can recreate this if I use “#include”, instead of “#import”, only works with “#import” (Not sure include exists in monkey2).
Maybe paste or attach the code here?
July 25, 2016 at 6:42 pm #2453Here ya go
Monkey12345678910'globals.monkey2Global MyVar := 1.0'Main.monkey2#import "globals.monkey2"Function Main:Void()Print MyVarEndFrom impixi’s post above
July 25, 2016 at 7:08 pm #2454Only other thing I can think of is try rebuilding mx2cc, in ted go Build>Scripts>Rebuild mx2cc. If you pulled the latest version from git I think you need to do that as well as the rebuild mods. Otherwise it’s a bit of an odd one that, maybe an OS issue of somekind?
July 25, 2016 at 7:27 pm #2455Im gonna download v1.0.2 and put the source into monkey and rebuild to see if that fixes this issue, to me its a weird issue to be honest.
July 25, 2016 at 9:02 pm #2457Right a update to v1.0.2 has fixed this issue after recompiling the whole thing it works fine now.
@Mark: I would update the binary to 1.0.2 so this doesnt rear its head again as it does make a brilliant product look bad which is a shame to be honest.
 - 
		AuthorPosts
 
You must be logged in to reply to this topic.