In a global script that uses AutoLoad, I set the value of a variable using a function But when I try to add to that variable in another scene, I get an error Instead of declaring a variable at the top of the script, I just put the function in the same format as var variable_name
'Invaild get index' Declaring a variable at the top of the script does not result in an error However, if you try to initialize a value using a function, the value does not change
-
I saw this video and created a fade in / out It's as simple as that, and it's fun to remember when I used Flash in the old days. But if you put it in the scene and run it, you will see texts and images already before the screen gets brighter
How can a fade in an animation node hide an object from the top?
I also studied about Tween. It was simple and easy. It was not supported by other engines, so I had to create one by directly calculating and assigning coordinate values This feature seemed to work. But on another node, there was a message that there was an error in "position"
At first I put a script in the RichTextLable so I thought it would be because the node did not have a property called position So I moved the script to the top 'Node' But the same error continues to pop up There was no problem with other object scenes
In this scene, I added a script to 'Node' and wrote position to tween, but I did not get the same error What's wrong with that?
I have three questions.
For number 1, you need to define the variables outside of the function so they are class variables (variables you can access from outside the node) instead of function variables (variables only available in that single function).
Using the code posted above, you can still have a score_init
function with class variables, you just need to make the variables you want class variables, and then in the score_init
function remove var
so from the beginning of each assignment so you are setting the class variable, not making a new function variable.
Something like this (untested):
var set_count;
var first_score;
var second_score;
var third_score;
var fourth_score;
var fifth_score;
var sixth_score;
var seventh_score;
func score_init():
set_count = 0;
first_score = “—“;
second_score = “—“;
third_score = “—“;
fourth_score = “—“;
fifth_score = “—“;
sixth_score = “—“;
seventh_score = “—“;
For the second question, I have no idea. I have not seen the tutorial and unfortunately right now do not have the time to see it. If what I wrote below does not work, let me know and I’ll see if I can make some time to check out the video.
Looking at the GIF, I would guess that the UI layer is above the node(s) that cause the transition in the scene. You can check this by adding a ColorRect node as a child of the transition node(s) and move the ColorRect underneath the UI.
If the UI draws on top of the ColorRect, then most likely the issue is the node order in the scene. If that is the case, then all you should need to do is move the transition nodes lower or higher (I cannot remember which right off) in the scene tree until the transition draws over the UI.
For the third question, honestly I do not know. What does the error message say? If the node is Node2D based, then position
should be defined and usable in a tween.
You are right that Control based nodes (like RichTextLabel) do not have a position
property. Instead you will need to use the rect_global_position
and rect_position
properties if you want to change its position.
Hopefully this helps :smile:
Oh, I made a stupid mistake...I thought that declaring a variable in a function would work outside of the function.
Instance scenes with transitions and UI are at the same level It is added as a child of 'Node' named manager I also created a large button image in the GIF file using the loop and added it as a child of 'Node'
When I first used a tween in a RichTextLable I got an error because of an incorrect index called 'position' So I moved the script to the parent node 'Node' and rewrote it But I still get the error 'Identifier not found: position'
1| No worries, it happens to all of us :smile:
2| Hmm, does the issue go away if you put the fade_effect
node as the last child in manager
? I think the problem is as I mentioned, that the UI, like score_board
and Button
are being drawn above fade_effect
because of where they are positioned in the scene. Moving fade_effect
below both nodes may fix the problem.
3| Hmm, that is strange. Looking at the code, I do not see anything that would be causing the issue. At the top of the code, is it extending Node2D
(or a node that extends Node2D) now?
Also, if you comment out the not working tween function call (just add #
to the beginning) and then copy-paste one of the working tween function calls from another script, does it still give you the error?
I did not see anything, but maybe it is a misspelled variable/function name or something? I get this issue sometimes and depending on the variable/function name, it can be hard to spot. I do not think that's the issue here, but it never hurts to double check.
- Edited
- This was totally misunderstood I thought the top of the list of nodes would be at the top In the script, I changed the order of visible = true I used a container called a node to load the fade effect node and create an object in it Now I see the scene I wanted.
3.It is not based on Node2d I just used 'Node' I made it in 'Node' in another script. There were no errors And the code in the above screenshot is copied from the script Commenting does not return any error I changed the top of the script to Node2D and There is a new error 'Invaild call. called Nonexistent function 'interpolate_property' ' If I change from Node2D to Node again, I get the error 'Identifier not found: position'
I can not do it now because I do not have time, but if I wake up, I will delete the script file tomorrow and create a new one. I may have encountered a problem when I ripped an existing script and loaded it from another node
I wrote 2, why start from 1? lol
- Edited
Because that's the way the forum software handles numeric lists in Markdown. Got to start with 1.
I solved my last problem. It was just a little typing error. :*