0 votes

How can I export a variable that allows only -1 and +1 as values?

export(int/float, -1, 1, 2) var direction

The declaration above only allows values of 0 and 1

in Engine by (33 points)
edited by

EDIT: I misread your code, this actually looks like a bug in your particular case.

However, if you wanted to allow values between -2 and 2 for example, and forbidding zero, it would currently not be possible. What I do in this case usually is to either expose the variable in a different way (multiplier instead of a divider for example) or just add a defensive if in the setter to be sure to not set incorrect values.
If you need only a few values though, maybe you could export it as an enumeration?

In 3.0 there have been mentions of improving range definitions https://github.com/godotengine/godot/pull/11599 but I don't know what's the state of it.

this seems a bug to me.
according to documentation for export, it should be possible i think.

in my short test,

export(int, -2, 2, 2) var direction

this allows -2, 0, 2

yeah, I misread the code (though part of my answer is still valid).
Maybe that's because the editor snaps with zero instead of the min value?

possibly. yeah.
the initial value of slider in the inspector should be handled properly.

I'll try with some mutator, thanks for info!

It could be a bug, maybe. I was thinking the same thing.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.