Animation played once godot - animation

I want to play a little Animated Sprite once, I mean only when the scene is visited the first time. I am trying to connect some signals in those ways:
on_scene_ready():
Animated_sprite.play("animation_name")
on_Animated_sprite_animation_finished():
Animated_sprite.hide()
And that's working correctly. But it repeats every time the scene is entered.
I tried a solution found on another forum that seemed to me similar to my issue: put a global variable (but doesn't work and I bet I make it bad)
var has_not_played = true
on_scene_ready():
if has_not_played:
Animated_sprite.play(animation_name)
on_Animated_sprite_animation_finished():
Animated_sprite.hide()
has_not_played = false
Any suggestions?
Thanks.

As long as you create a new instance of the scene (what you most likely do, as we can see) your has_not_played variable will always be instanced as true as well. Setting it to false will not help here then.
One simple solution would be to create a autoload script to hold all level informations you need your programm to save, after the scene was exited.
These are infos you most likely want to save as well, when your game is saved.
As an example you could do something like this.
Create a script LevelInfos.gd. Mine looked like this:
extends Node
var level_infos : Dictionary = {
"level_1" : {
"start_animation_played" : false
}
}
Then add this to Project -> project settings -> Autoload with the NodeName LevelInfos.
Now you can reuse your existing code like this:
on_scene_ready():
if not LevelInfos.level_infos["level_1"]["start_animation_played"]:
Animated_sprite.play(animation_name)
on_Animated_sprite_animation_finished():
Animated_sprite.hide()
LevelInfos.level_infos["level_1"]["has_already_loaded"] = true
This should make it so it only gets played the first time the scene is visited, after you start the game.
Code wise I guess it would be better to make dedicated variables instead of using a dictionary, but it works as a example and could be easily saved as an JSON, if needed.

Related

Wait or know when is load the assets of entity completely

I would like to be able to identify when the object is already fully loaded in the engine
const box = new Entity()
box.getComponent(Transform).position.set(3, 1, 3)
var model=new GLTFShape()
box.addComponent(model)
engine.addEntity(box)
I mean something like this:
model.OnLoaded(()=>{/*The model load in Cache*/})
or
await engine.addEntity(box)
or
engine.addEntity(box,()=>{/*charging is complete*/})
I can't find a way to do this
any suggestions other than waiting without knowing what happens?
Unfortunately, as it stands now, there is no real concrete way to know when an asset is loaded. This feature (onLoading, onLoadComplete, ect) may be included in a future update. I believe it's on the roadmap. In the meantime, you may want to put a delay of some kind with either a setInterval or otherwise and set it to a few seconds, and then call whatever code you want.
There are workarounds, but they are crazy and I wouldn't recommend it, for your own sanity sake.

Changing values of numbers in CodeMirror by using scrubbing addon

I'm having trouble with CodeMirror. I'm trying to add in live number scrubbing, similar to Brett Victor's example, and Khan Academy's capability, but I am not having too much luck.
I can't post links, but I found this library which kind of gets the job done (made by user FWeinb on GitHub) which can kind of accomplish what I'm looking for, but I've noticed that although the numbers appear to have been changed, as soon as I do something like press enter in CodeMirror, then the value of the variable resets to what it was originally.
I'm using ReactJS, and I am not too sure how to fix this. I'm trying something a little ludicrous by calling this.replaceRange every time the contents are being changed, but there must be a better way. Here is a snippet of my code. It's not what I want it to be ideally, but just for testing purposes:
this.cm.on('dblclick', this.handleDblClick.bind(this))
...
handleDblClick() {
let matches = document.querySelectorAll(".cm-number");
let scrub = new Scrubbing (matches[0],
{ driver :
[
Scrubbing.driver.Mouse,
Scrubbing.driver.MouseWheel,
Scrubbing.driver.Touch
]
})
matches[0].addEventListener('DOMSubtreeModified', () => {
//console.log('change detected')
})
}
So I know that currently the scrubber edits this: <span class="cm-number"></span>, but that the actual underlying data isn't updating with the scrubber, nor is it persisting. Can anyone shed some light on what I should be doing here so that the value of the variable within the editor is updating live with the scrubber, and so that the value persists upon a new action?

Why I can't add a new variable to the Session in Classic ASP?

So, I thought that I could add a new element to the user Session to add some functionality.
I honestly thought I could do this:
SomeFunction(param1, NEWparam)
{
Session("MyNewParam") = NEWparam;
//So this would create a new session element called 'MyNewParam', right..?
...
}
That gets called when the user presses a button and then another webpage loads up.
The result, with this new line of code: The next web page doesn't load. Nothing happens.
Any and all comments are welcomed.
Solutions or helpful comments would be great.
Your syntax is right. However, I've run into an issue before where Classic ASP didn't want to take a session variable if it wasn't explicitly typed though. I'm not sure why this is, but it's worked for me in the past.
Session("MyNewParam") = parseInt(NEWparam);
Obviously, you could use String(), parseFloat()... or whatever. As I said, the syntax is right otherwise, so if the code isn't working you may want to start looking at other parts of the function that might be causing the problem.

Can a Joomla module "know" what position it's in?

I'm fairly new to Joomla (I've been more of a Wordpress guy) and I have a question about module positions.
Can a module know what position it's in. For instance can I do something like this:
if(modulePosition =='left'){
Do this...
}else{
Do that...
}
It seems easy enough, but I've searched for hours and can't find anything that will help me with that. I know there is a countModules function but from what I can tell, that just checks to see if the module is active or not.
Thanks for your help!
I found the answer! Mostly thanks to #Hanny. His idea of using the modules id got me googling for that and I came across the answer. For anyone else that happens to be looking to do something similar here it is.
You use a global variable $module (who'd a thought, right?)
So my code now looks like this:
$class = '';
if($module->position == 'position1'){
$class = 'class1';
}
and so on...
Pretty simple, huh?
To find out what else you can do with the global variable $module just put this in your code and see what info you can use:
echo(print_r($module));
Thanks for all your help!
The short answer is 'yes', you'll assign a module a position based on your template. When it shows up you can have conditionals like that regarding that position (different templates have different naming conventions for positions, so make sure you know what they are before coding).
For example, some use "Position12", others may use "leftcol", etc. You just have to check in the template files to see (you can check the .xml file in the template directory to see the positions listed in the template, or look in the index.php file for the jdoc includes).
In some of my experience, the only time you'll really ever need code like that is in the core layout files of the template (for example, if you have different widths of columns depending on modules being present or not), otherwise there won't really be a time where you 'may or may not' have a module showing up - because you'll explicitly be telling them where to be and when on the back end.
I tried to comment under john's solution but I don't have a enough rep points-- I wanted to add it doesn't matter what you name the module position in your template case-wise the position name you get back from $module->position is always all lowercase regardless of how you named the position in the template... ie. in your template xml somewhere you might have topBar position will be named 'topbar' not 'topBar' when you try to check it with
if($module->position == 'topBar') //always false... use instead
if($module->position == 'topbar') //what you need to use
I'm going to disagree with Hanny. I think the answer is no, not as you describe.
The template knows when it has reached a module position, and it gets a list of modules assigned to that position, then calls for them to be rendered. But it doesn't pass that information on. It's not stored in JApplication or JDocument etc either (like, nothing stores where in the template the rendering is up to or anything).
There are some hacky ways to almost get what you want though. If you know the template positions you need to search (sadly there's no easy method for getting this from the template - otherwise you could parse your template's .XML file for <position> elements...), then you could do something like:
<?php
$positions = array('left', 'right', 'top', 'bottom')
$found_in = false;
foreach ($positions as $cur_position)
{
$module_positions = JModuleHelper::getModules($cur_position);
foreach ($module_positions as $cur_module_in_pos)
{
if ($cur_module_in_pos->module == 'mod_MYMODULE')
{
$found_in = $cur_position;
}
}
}
if ($found_in)
...
Of course, this doesn't work well if your module is included multiple times on the page, but maybe that's an assumption you can make?
Otherwise it'd be up to hacking the core - you could use a JDispatcher::trigger() call before the template calls a module, set some var etc. Unfortunately there's no such event in core to start (a pre_module_render or something).
A module instance is assigned to a single position and this is stored in the database and normally you would style the position in the template. A module instance can only be assigned to one position. So while it's an interesting question, it's not really a practical one.
The exceptions to this are the following:
loadposition ... you might want to know if a module is being loaded using the plugin because this would put it potentially somewhere besides the styled area for the position. THough i would recommend always making a new instance for this precisely so you have more control.
loadmodule ... module loaded by name using the plugin. In this case again you are probably better off making a new instance of the module and styling it. Also I'd put it in a span or div anyway, depending what it is.
jdocinclude:module ... loading a module directly in a template. Again if you are doing this I would wrap it in a span or div. In this case you are also allowed to include a string of inline styles if you like that kind of thing.
Rendering the module to a string and echoing it, again that is basically a very customized solution and you would want to set the styles and options.

Multiple GeoCoordinateWatchers in WP7 Cause Bad Data

If I have multiple GeoCoordinateWatchers in a WP7 application, they seem to cause conflict with one another. I would assume that if I have a watcher setup like:
new GeoCoordinateWatcher(GeoPositionAccuracy.High) { MovementThreshold = 0 }
and another setup like:
That the value from the first should be extremely accurate whereas the second one should be used as a point of reference.
new GeoCoordinateWatcher(GeoPositionAccuracy.Default) { MovementThreshold = 1000 };
However, the second one causes the first coordinates to jump all over the place. If I comment out the second, the first works as expected. Any idea why?
Try setting the same accuracy and see if you get the same values.

Resources