anybody know where there is a tutorial on setting up a toggle key so e is engine on and e is engine off
has anybody got a tutorial on how to setup a toggle key
It really depends on how you want to go about making a toggle. There are several ways to go about it, but I found using a class variable (a variable outside of any/all functions) is a pretty easy way to add a toggle.
Here is some example code. I have not tested it, but I think it will work. Also, I wrote the code to work with Godot 3, but it should also work with Godot 2 with some minor changes:
# Example toggle variable:
var engine_powered = false;
func _process(delta):
if Input.is_action_just_pressed(“toggle”):
# This flips the Boolean’s state.
# If engine_powered is true, then !engine_powered will make be false.
# By setting engine_powered to !engine_powered, it will flip the value of
# engine_powered to its opposite value (true->false, false->true)
engine_powered = !engine_powered;
if (engine_powered):
print (“Engine is on!”)
else:
print (“Engine is off!”)
Hopefully this helps :smile:
your a star!!! will give it a go tomorrow!!! goodnight...
i just cant understand why im having an indentation error
extends StaticBody2D
export (int) var SPEED var velocity = Vector2() var screensize var engineStarted = false
func _ready(): screensize = get_viewport_rect().size
func _process(delta): velocity = Vector2() if Input.is_action_just_pressed("toggle") -------------------- no matter where im moving this line its red!!!
seems to be tab!!! when i use four spaces its fine...strange
also the code you suggested doesnt work its just stuck on engine off...any ideas
i cant stress how valuable your help has been...thanks!!!
lol working great!!! was the input key that was the problem!!!
thanks a ton!!!
last question
how can you speed up an animation via scripting....would be nice to have the rotors turn slower to start then speed up for take off!!!...in my element here
something is really up with indentation....how many tabs after an if for code? i know python is 1...but some ifs are fine then down the list in the same block its complaining....driving me mad!!!
- Edited
The godot internal editor uses a setting of 4 spaces per tab, so more than likely whatever editor you are using you need to change your preferences to reflect that.
edit: I'd also appreciate it if you didn't start a new topic for each of these related questions[1][2]. Also you keep posting them into general chat while they belong in the programming, I'll move them myself for now though. ;)
hi im using the internal editor and my settings are the same as yours...strange but im definitly having a problem
Hmm, try enabling the "Convert indent on save" in those same options then. That might help.
hey Megalomaniak
will give it a go
also:how can you speed up an animation via scripting speed(FPS)....would be nice to have the rotors turn slower to start then speed up for take off!!!
error where the line was,was not a problem before saving changes you suggested...what is a better alternative for editor...this is driving me batty! what do you use?
could it be due to the fact that i copied some code from a web site? if so should it be typed out from scratch in a new script?
@warrenb said:
![]()
error where the line was,was not a problem before saving changes you suggested...what is a better alternative for editor...this is driving me batty! what do you use?
The reason you are getting an error on line 21 is because line 20 uses spaces for its indentation, while the rest of the code uses tabs. Just replace the spaces with tabs and the error should go away.
You can tell how many tabs you are using and whether a line is using tabs or not based on how many of the >|
symbols are visible on the left side of the editor. Because line 20 has no >|
symbols, that means it is using spaces. Godot will allow you to use spaces or tabs in a project, but each code file has to use the same indentation method. Since the rest of the code is using tabs, I would recommend just replacing the spaces in line 20 with tabs.
Side note: You can have Godot convert from spaces to tabs automatically by clicking the "Edit" button, and selecting the "Convert Indent To Tabs" button. You can convert from tabs to space the same way, just press the "Convert Indent To Spaces" button instead.
- Edited
ooooooooooooooooooooh!!!!! thanks man!!! glad i showed the screen shot...couldnt get my head around it...so you can use spaces or tabs...just be consistent...does it matter which you use?...ok did that...working perfectly!!! hey not to be a nag im really stuck on my project...very few tutorials out there...how can you speed up an animation via scripting speed(FPS)....would be nice to have the rotors turn slower to start then speed up for take off!!! ...just a clue would be nice...
@warrenb said: ooooooooooooooooooooh!!!!! thanks man!!! glad i showed the screen shot...couldnt get my head around it...so you can use spaces or tabs...just be consistent...does it matter which you use?...ok did that...working perfectly!!! hey not to be a nag im really stuck on my project...very few tutorials out there...how can you speed up an animation via scripting speed(FPS)....would be nice to have the rotors turn slower to start then speed up for take off!!! ...just a clue would be nice...
Happy to help :smile:
As for making the animation speed faster, it depends on what you are using for your animation.
If you are using a AnimationPlayer
node you can change the playback_speed
property of an AnimationPlayer
node and that will speed up or slow down any animation the AnimationPlayer
node is playing. You can read more about AnimationPlayer in the documentation.
Though, looking at the code above, you are using a AnimatedSprite
, correct? While I do not have any experience with using AnimatedSprite
nodes myself, as I've always just used Sprite
nodes and sprite sheets instead, it looks like you can change the speed of the animation by changing the speed of the SpriteFrames resource, according to this QA answer.
I also found this closed issue on Github that shows some example code on how to change the speed of a animation called "walk", though it is a few years old so the syntax has probably changed. Still, it may help you figure out how to change the speed of the SpriteFrames resource, so I'd take a look at the code there if you are having difficulty.
If you are using a different node, then I'd Google something like "Godot [insert node name here] change animation speed" and see if you can find a result that works.
Hopefully this helps :smile:
will look into what you are saying and get back to you....really...thanks so much!!!
tried this $AnimatedSprite.set_animation_speed(playerHeli,30) playerHeli is the animation name everything i tried just throws an error lol
$AnimatedSprite.get_sprite_frames().set_animation_speed("start", 10.0) $AnimatedSprite.play("start")
this was the best i could come up with...but the helicopter just disappears
@warrenb said: $AnimatedSprite.get_sprite_frames().set_animation_speed("start", 10.0) $AnimatedSprite.play("start")
this was the best i could come up with...but the helicopter just disappears
Do you have an animation in your AnimatedSprite
called start
? The name of the animation has to be exactly the same, including capitalized letters. start
and Start
would count as two different animations.
I have not really used AnimatedSprite nodes, but the sprite disappearing seems like it cannot find the animation. One way you can test to see if the animation exists within your AnimatedSprite is with the following few lines code:
if $AnimatedSprite.frames.has_animation("start") == true:
print ("animation with name *start* exists!")
else:
print ("animation with name *start* does not exist!")
(Side note: $AnimatedSprite.frames
should work just like $AnimatedSprite.get_sprite_frames()
in Godot 3. If you are using Godot 2, then you'll need to use the get_sprite_frames
function)
My hunch is that the name is different and so the helicopter disappears since there is no animation to change to. I could be wrong though.
Does the debugger showing anything after the helicopter disappears? It may be helpful in figuring out what is going on.
I was thinking of something. You said the name of the animation is playerHeli
, correct? If that is the animation you are wanting to change, then the following code should work:
$AnimatedSprite.frames.set_animation_speed("playerHeli", 10.0)
$AnimatedSprite.animation = "playerHeli"
I think the line above, $AnimatedSprite.animation = "playerHeli"
, will have the same effect as calling the play
function, though if the animation is already playerHeli
, then it shouldn't reset the animation. If it does not work or gives an error, then all you should need to do is replace it with $AnimatedSprite.play("playerHeli")
.
But other than what I wrote above, I'm not really sure. I primarily use the 3D side of Godot and have never really used many of the 2D nodes, including AnimatedSprite
. Hopefully this helps though!