Behaviour dropdowns (ENUM)
by Ronny Bangsund · in Torque Game Builder · 02/27/2011 (4:31 pm) · 10 replies
I've been trying to make things easier for the artist/musician by generating datablocks for music and sounds when the editor starts, and have that bit working fine. Now the problem is the actual dropdown box for the music in a behaviour I made for level defaults.
I create a list of names, made from stripping them down to just the basename ("audio/music/menu.ogg" becomes "menu"). This shows up as you'd expect in the dropdown, and the names have one TAB symbol as the separator between each entry (and only there). I also tried \n, with no difference.
But the big problem we have is that the second entry never saves. If I save the level with any other choice, the behaviour is stored in the object with all arguments intact (_behavior0 = "LevelDefaults Music menu"). But if the second choice is selected, it's stored without arguments (_behavior0 = "LevelDefaults").
Am I doing something wrong? Does the documentation lie? Did I somehow break the editor while fixing other things? Anyone else noticed strangeness like this?
I create a list of names, made from stripping them down to just the basename ("audio/music/menu.ogg" becomes "menu"). This shows up as you'd expect in the dropdown, and the names have one TAB symbol as the separator between each entry (and only there). I also tried \n, with no difference.
But the big problem we have is that the second entry never saves. If I save the level with any other choice, the behaviour is stored in the object with all arguments intact (_behavior0 = "LevelDefaults Music menu"). But if the second choice is selected, it's stored without arguments (_behavior0 = "LevelDefaults").
Am I doing something wrong? Does the documentation lie? Did I somehow break the editor while fixing other things? Anyone else noticed strangeness like this?
About the author
(Waiting for UTF-8 to work again!) ಥ_ಥ
#2
When I choose 2 in the dropdown, there are no arguments saved. The resulting behaviour line in the sprite looks like this:
So the MyChoice argument and its choice are not included only when I choose #2 in the list. Not sure what's broken, as I haven't been anywhere near code I think has anything to do with that in the engine itself or the editor scripts :/
02/27/2011 (8:35 pm)
Cheers, here's a stripped down behaviour:if(!isObject(Broken))
{
%template = new BehaviorTemplate(Broken);
%template.friendlyName = "Broken test";
%template.behaviorType = "My stuff";
%template.description = "Add fields.";
%list = "1" TAB "2" TAB "3" TAB "4";
%default = getWord(%list, 1);
%template.addBehaviorField(MyChoice, "An example list", ENUM, %default, %list);
}
function Broken::onAddToScene(%this)
{
echo("@@@@@@@@@@ Broken: My choice is currently " @ %this.MyChoice);
}When I choose 2 in the dropdown, there are no arguments saved. The resulting behaviour line in the sprite looks like this:
_behavior0 = "Broken";
So the MyChoice argument and its choice are not included only when I choose #2 in the list. Not sure what's broken, as I haven't been anywhere near code I think has anything to do with that in the engine itself or the editor scripts :/
#3
However, it works just fine if you set an empty string as a default value, which is actually better design than using the first or any other entry of a list for that.
02/28/2011 (1:37 am)
Interesting. This code actually does not save with second option.However, it works just fine if you set an empty string as a default value, which is actually better design than using the first or any other entry of a list for that.
#4
The intended use is for default backgrounds and background music in levels, which we'll always want. So having a default is definitely useful and desirable.
So that means it's broken. This is not what the documentation says it should do.
02/28/2011 (1:56 am)
Better design in some programs, certainly. But not in mine ;)The intended use is for default backgrounds and background music in levels, which we'll always want. So having a default is definitely useful and desirable.
So that means it's broken. This is not what the documentation says it should do.
#5
If your music player has preferred default track, it should probably be explicitly defined in its member field or global variable, rather than relying on first entry of the list. How you create and use your list may change in the future, and first entry may not always be what you expect it to be.
03/01/2011 (12:51 am)
It is broken to a some degree, but unlike other bugs this one does not require workaround and actually helps you create better, more robust code.If your music player has preferred default track, it should probably be explicitly defined in its member field or global variable, rather than relying on first entry of the list. How you create and use your list may change in the future, and first entry may not always be what you expect it to be.
#6
P.S.:Did you forget to log in with your real account? You've been posting a long time, and no sign of a license on your account.
03/01/2011 (1:03 am)
It's not a music player. I'm making it so it's easier for the other team member to add music. It DOES NOT MATTER what the first entry is - I know it's always a music track because I'm getting a list of tracks in a directory we put files into. My code is fine, thank you very much.P.S.:Did you forget to log in with your real account? You've been posting a long time, and no sign of a license on your account.
#7
03/01/2011 (4:16 am)
Kind of... I'm going to use this account yet for some time, hope it doesn't bothers you much.
#8
03/01/2011 (4:21 am)
It does. We see pirates lurking far too often.
#9
03/01/2011 (8:59 am)
That wasn't a question but... whatever
#10
06/14/2011 (5:56 am)
This behavior results from the assumption that there is NO NEED to write out the fields that have default values. Your code should not change its behavior whether the default values are written out or not -- the variable itself will still hold the correct value. At least, it should be. The only case is when your default value is not constant, but I think it should not be named "default" then.
Associate William Lee Sims
Machine Code Games