Your test variable is of the type Test*. This is a pointer to an object of type Test. Since it is a pointer, it is neither a struct nor a class. You have to follow the pointer and then do the .
(*test).Add = 1;
Another way of writing the exact same thing is
test->Add=1;
You could have enriched Test*, so that test.Add makes sense.
enrichTest*{intAdd{set{this->Add=value+2;}}}
That is why it is telling you it has to be a struct, class or something which is enriched.
Well.. yes, but it is because your variable is a pointer (although you have to make it a pointer when you use classes). You can make pointers to other stuff as well, and then you also have to use * or ->. Like
You can't. There is no way for me to reliably send parameters to triggers when their event is fired, so It would be hard to tell the trigger what class object it is currently in. Therefore, triggers inside structs/classes are not possible. You could argue that it should still be possible with static methods, but it currently isn't.
When I need something like that, I usually have a list of all allocated classes (Add to the list in the constructor, and remove from it in the deconstructor). Then I make a global trigger, that runs through each allocated object, and does what it needs to do. Like this
usingCollectionsInitializer{Test.Instances=newArrayList<Test*>();}classTest{//I uploaded a library containing the arrayliststaticArrayList<Test*>*Instances;inti;boolrunTriggerOnMe;Test(inti,boolrunTriggerOnThis){Instances->Add(this);this->i=i;runTriggerOnMe=runTriggerOnThis;}~Test(){Instances->Remove(this);}}TriggerTestTrigger{events{TriggerAddEventUnitStartedAttack(TestTrigger,null);}actions{intcount=Test.Instances->Count;//No need to call this each iteration - unless you modify the collectionfor(inti=0;i<count;i++){Test*test=Test.Instances->Get(i);if(test->runTriggerOnMe){//Do stuff}}}}
No, I don't really have a master plan as to what features are to come.. I kind of take it one step at the time. For next one, I'm adding reliable null pointer checks, nested namespaces, and probably some bugs because of all of this rewriting. I also think I'll allow sync/async invokes on more than just global methods.
First off, let me say, great project! You are awesome!
About a year ago I started a map project using Andromeda. I recently returned to working on it, and Andromeda is no longer updated, where your language has grown significantly. As such, I decided to switch my development over to gpp . I'm still trying to get the hang of your language.
I'm having a problem using arrays of objects. I'm not sure how to create a multidimensional array of objects that works reliably, and I am getting bizarre behavior if I try to create an array of pointers. My testing so far makes me think it is the same for structs and classes. Here is my data declaration:
At first, I had tried to do the HeroData declaration as HeroData*[], an array of pointers to a the HeroData struct. However, it seems whenever I do that, all entries in the array point to the same object. The following shows the error:
Am I just using arrays of pointers wrong? The problem did go away for the structs when I declared it as a straight array instead of an array of pointers, but I suspect it is still present in UnitList*[][]. Since that one is a pointer to a class, I am required to declare it as a pointer or else it gives me the "classes must be dynamic" error.
Let me know if I wasn't clear enough about anything, or if you'd like to see some map code.
Edit: Apparently using the plusplus operator makes my text appear green? Well that's weird!
It outputs 10, 5 as expected. Same thing if I declare PlayerData as a struct - though if you only use it in dynamic contexts, use classes.
Also, you don't really need the StringToText calls.. As long as you didn't define an overload for the function that takes ints in second parameter, the compiler will convert it to text on its own.
I'm not sure why that worked for you, but not for me. I tested mine inside of a much larger beast, but this was early enough in execution that it shouldn't have mattered. I wish I could test it more, but unfortunately my work laptop is picky about running the editor.
Attached is a copy of part of my map code. I believe it is enough. I had to make some adjustments for clarity without the benefit of a compiler to double-check me, but I think it will compile fine.
Did not know the compiler would handle the string to text conversion on its own, that's cool!
Also, I would like to mention a small bug that I found the other day. If I do something like:
The code coloration will not catch the last */ . It will list the entire rest of my code as comments. It still compiles (parses?) correctly, it is just the color that's off.
I still have no problems, if I add the code in an initializer along with your code. I did make an error in the code I posted previously though.. The array is not created.. The first statement should be
Thanks, you were right. I was thinking in terms of C arrays where you would declare an array of objects all in one statement, instead of first declaring the array of pointers, then instantiating new objects for each pointer. I was thinking the second declaration was implicit, not in terms of "pointer to a pointer".
As a suggestion for a feature, did you consider allowing a conversion from int to fixed, possibly with a warning? I understand you obviously would lose precision, but my experience is largely with C where I have learned not to care. Galaxy provides a function for this already:
intTruncI(fixedx)
Or, you could just make me do the type conversion explicitly. :)
Edit:
Also, I just found a small bug. I was trying to create an infinite loop by using for(;;), which does appear to be valid in straight Galaxy. This crashes the compilation job. I sent a report via the in-editor tool.
What is the difference between TruncI(fixed) and FixedToInt(fixed)?
if you write int i = (int) f; it will insert a call to FixedToInt. I don't think I will create an implicit conversion from fixed to int, since as you say, we lose information.
I just started working with enrichments, and the editor crashed on me, when attempting:
UnitFromId(233).evasion=.5;
with evasion obviously being a unit enrichment of type fixed. Changing this to:
unitu=UnitFromId(233);u.evasion=.5;
fixed the crash and works just fine ingame.
Also, I was not able to send the crash log, it complained about my internet connection, which works just fine.
Another suggestion: What about showing the source script in the trigger editor, if you choose to save the galaxy++ source files into the map? You could make your editor generate folders and custom script objects to show up in the trigger editor, instead of just import the stuff without a chance to look at the script from within the galaxy editor. Obviously, you would not be able to change the script within the map and the syntax highlighting would be messed up, but you would at least be able to see the script without actually having your editor available. You could also include some advertising, like "Want to code like this? Try Galaxy++!" :p
This will be helpful for people looking at maps, which use G++
You could also include some advertising, like "Want to code like this? Try Galaxy++!" :p
This will be helpful for people looking at maps, which use G++
That on the other hand would be quite nice. Maybe you could also let the user define a text that is added to the map, so you could add something like: "If you're looking for the map script source, goto [email protected]"
I don't think that looking at the compiled output is of much help since its pretty obfuscated and you can already see that with the import manager.
I might have used the wrong formulation here, I am not talking about the compiled output, I am talking about the source code. The compiled output will be replacing the map script, of course, but there is the option to save and load the source code to the map as well.
Currently, this only includes the g++ source files in the map's mpq archive, and you can't look at their contents within the import manager, because they don't have a supported file ending. But since the triggers are unused for an injected map script anyway, we might as well use them to display the source code. People could have a look at the code, even though they won't be able to change anything.
Another question: How do I declare and use an array of classes?
Foo*bar;
works for Foo being a class, but
Foo[1]*bar;
gives me an error message:
"Damage System\Damage System[25, 1]: You can only make dynamic instansiations of classes."
Your test variable is of the type Test*. This is a pointer to an object of type Test. Since it is a pointer, it is neither a struct nor a class. You have to follow the pointer and then do the .
(*test).Add = 1;
Another way of writing the exact same thing is
You could have enriched Test*, so that test.Add makes sense.
That is why it is telling you it has to be a struct, class or something which is enriched.
OK THX
And i always have to write "->" to get or send data to class? - if i dont want to write enrich?
Well.. yes, but it is because your variable is a pointer (although you have to make it a pointer when you use classes). You can make pointers to other stuff as well, and then you also have to use * or ->. Like
This can be used when any modifications other methods make to your variable should be saved. When you run foo, 42 will be displayed on screen.
can u help me? How can i create a local trigger something like this:
plz help m
You can't. There is no way for me to reliably send parameters to triggers when their event is fired, so It would be hard to tell the trigger what class object it is currently in. Therefore, triggers inside structs/classes are not possible. You could argue that it should still be possible with static methods, but it currently isn't.
When I need something like that, I usually have a list of all allocated classes (Add to the list in the constructor, and remove from it in the deconstructor). Then I make a global trigger, that runs through each allocated object, and does what it needs to do. Like this
Ok thx for help
Woo! Today it is one year since the first release of the editor. :)
I had hoped to get next version out for today, but those nested namespaces requires a hell of a lot of rewriting..
Happy anniversary!
It has gone a long way since then ;) (if this is anywhere close to correct english)
Whoo, congrats :)
Btw. is there any kind of roadmap or a list on what you're planning to add to galaxy
++
or the editor?Thx :)
No, I don't really have a master plan as to what features are to come.. I kind of take it one step at the time. For next one, I'm adding reliable null pointer checks, nested namespaces, and probably some bugs because of all of this rewriting. I also think I'll allow sync/async invokes on more than just global methods.
First off, let me say, great project! You are awesome!
About a year ago I started a map project using Andromeda. I recently returned to working on it, and Andromeda is no longer updated, where your language has grown significantly. As such, I decided to switch my development over to gpp . I'm still trying to get the hang of your language.
I'm having a problem using arrays of objects. I'm not sure how to create a multidimensional array of objects that works reliably, and I am getting bizarre behavior if I try to create an array of pointers. My testing so far makes me think it is the same for structs and classes. Here is my data declaration:
HeroData, BaseData, PlayerData - structs UnitList - object
At first, I had tried to do the HeroData declaration as HeroData*[], an array of pointers to a the HeroData struct. However, it seems whenever I do that, all entries in the array point to the same object. The following shows the error:
Am I just using arrays of pointers wrong? The problem did go away for the structs when I declared it as a straight array instead of an array of pointers, but I suspect it is still present in UnitList*[][]. Since that one is a pointer to a class, I am required to declare it as a pointer or else it gives me the "classes must be dynamic" error.
Let me know if I wasn't clear enough about anything, or if you'd like to see some map code.
Edit: Apparently using the plusplus operator makes my text appear green? Well that's weird!
I might need more of your code than that. When I run the following script
It outputs 10, 5 as expected. Same thing if I declare PlayerData as a struct - though if you only use it in dynamic contexts, use classes.
Also, you don't really need the StringToText calls.. As long as you didn't define an overload for the function that takes ints in second parameter, the compiler will convert it to text on its own.
I'm not sure why that worked for you, but not for me. I tested mine inside of a much larger beast, but this was early enough in execution that it shouldn't have mattered. I wish I could test it more, but unfortunately my work laptop is picky about running the editor.
Attached is a copy of part of my map code. I believe it is enough. I had to make some adjustments for clarity without the benefit of a compiler to double-check me, but I think it will compile fine.
Did not know the compiler would handle the string to text conversion on its own, that's cool!
Also, I would like to mention a small bug that I found the other day. If I do something like:
The code coloration will not catch the last */ . It will list the entire rest of my code as comments. It still compiles (parses?) correctly, it is just the color that's off.
I still have no problems, if I add the code in an initializer along with your code. I did make an error in the code I posted previously though.. The array is not created.. The first statement should be
Maybe that is your problem too.
Thanks, you were right. I was thinking in terms of C arrays where you would declare an array of objects all in one statement, instead of first declaring the array of pointers, then instantiating new objects for each pointer. I was thinking the second declaration was implicit, not in terms of "pointer to a pointer".
As a suggestion for a feature, did you consider allowing a conversion from int to fixed, possibly with a warning? I understand you obviously would lose precision, but my experience is largely with C where I have learned not to care. Galaxy provides a function for this already:
Or, you could just make me do the type conversion explicitly. :)
Edit:
Also, I just found a small bug. I was trying to create an infinite loop by using for(;;), which does appear to be valid in straight Galaxy. This crashes the compilation job. I sent a report via the in-editor tool.
What is the difference between TruncI(fixed) and FixedToInt(fixed)?
if you write int i = (int) f; it will insert a call to FixedToInt.
I don't think I will create an implicit conversion from fixed to int, since as you say, we lose information.
I didn't realize gpp supported casting. That works perfectly!
I just started working with enrichments, and the editor crashed on me, when attempting:
with evasion obviously being a unit enrichment of type fixed. Changing this to:
fixed the crash and works just fine ingame.
Also, I was not able to send the crash log, it complained about my internet connection, which works just fine.
Another suggestion: What about showing the source script in the trigger editor, if you choose to save the galaxy
++
source files into the map? You could make your editor generate folders and custom script objects to show up in the trigger editor, instead of just import the stuff without a chance to look at the script from within the galaxy editor. Obviously, you would not be able to change the script within the map and the syntax highlighting would be messed up, but you would at least be able to see the script without actually having your editor available. You could also include some advertising, like "Want to code like this? Try Galaxy++
!" :pThis will be helpful for people looking at maps, which use G
++
I don't think that looking at the compiled output is of much help since its pretty obfuscated and you can already see that with the import manager.
That on the other hand would be quite nice. Maybe you could also let the user define a text that is added to the map, so you could add something like: "If you're looking for the map script source, goto [email protected]"
I might have used the wrong formulation here, I am not talking about the compiled output, I am talking about the source code. The compiled output will be replacing the map script, of course, but there is the option to save and load the source code to the map as well.
Currently, this only includes the g
++
source files in the map's mpq archive, and you can't look at their contents within the import manager, because they don't have a supported file ending. But since the triggers are unused for an injected map script anyway, we might as well use them to display the source code. People could have a look at the code, even though they won't be able to change anything.Another question: How do I declare and use an array of classes?
works for Foo being a class, but
gives me an error message:
"Damage System\Damage System[25, 1]: You can only make dynamic instansiations of classes."