/r/godot

Photograph via snooOG

The official subreddit for the Godot Engine. Meet your fellow game developers as well as engine contributors, stay up to date on Godot news, and share your projects and resources with each other. Maintained by the Godot Foundation, the non-profit taking good care of the Godot project - consider donating to https://fund.godotengine.org/ to keep us going!

Looking for Godot?

Download the engine, Donate to the fund, Follow us on socials & more! Official Link-Collection

Subreddit rules:

Apply to become a mod!

1. English only, please

For moderation purposes, please stick to the official language of this subreddit, both for posts and comments.

2. Follow the Code of Conduct

Read it here
Breaching the code is a banable offense. In particular, we won't tolerate discrimination or bullying of any kind.

3. Use appropriate flairs for your posts

If you don't, we maintain the right to delete the post in violation of this rule. Wiki page to describe the flairs coming soon...

4. Post memes with consideration

They must have the "fun & memes" flair, be related to Game Development, and the topic/content cannot breach the Code of Conduct. Do not spam memes.

5. Promotion only under certain circumstances

To avoid plain advertisements to an audience of game developers, we offer a handful of themed promotion flairs, so you can show off your game with purpose instead - if your post idea does not fit any of them, please reconsider posting. Additionally, we require posters in this flair category to stay active and respond to comments under their promotion - otherwise we may delete the post.

6. Stay on topic

This is a subreddit about the Godot Engine. While related Game Development topics are not forbidden, please make sure to tailor them towards the Godot project. This means no art posts unless you are talking about the technical side of things - there are enough other outlets to post your pretty renders and concepts.

7. Getting started

Reference this starter guide before asking for general advice/help. Posts asking "Where do I start?" will automatically be locked, due to this subreddit overflowing with them in the past.

8. Tech Support guidelines

Repeated neglect of these can be a bannable offense.
1 - Consult the docs first
2 - Search for your question before posting
3 - Concrete questions/issues only! This is not the place to vaguely ask "How to make X" before doing your own research.
4 - "Can Godot be used to make this game?" Yes.
5 - Don't post photos of your screen, screenshots are okay, direct code with formatting or a pastebin is best
6 - We recommend checking the official forum as well.

9. Copyright & AI-generated content

For legal reasons, you may only post content that you are the rights-holder of. This means you are required to credit assets according to the licenses you acquired them under. Some licenses permit sharing content without listing your sources, others do not. In particular, this means that AI-generated content needs to veritably stem from a model which was trained only on data submitted with the original creator's consent. If you cannot prove this to be the case upon request, we remove your post.

/r/godot

220,995 Subscribers

0

Can someone please explain why my code isn't coding like I want it too? I tried.

I want it to create a "border" over every country and then remove that when mouse moves over a new country and a new border appears. The first part of the logic works. But when I try to remove the previous pixel editing's from the old country by applying the old image, it doesn't work for some reason. As you can see in the video, it doesn't wipe the border over the last country when moving to a new one, although the code should theoretically allow that to happen (The node tree is also in the vid btw). Also I don't think this has to do with the != not the same as is not thing going around. Thanks for any help.

Here's the whole code for that script:

extends Control

var world_image : Image

static var default_image : Image

var script_ready = false

var old_country = ""

var new_country = ""

var height

var width

var colors_to_value = {

`"Red": Color8(235, 52, 96, 255),`

`"Yellow": Color8(246, 167, 30, 255),`

`"Blue": Color8(42, 177, 196, 255),`

`"Dark Blue": Color8(52, 64, 106, 255),`

`"Green": Color8(176, 209, 56, 255),`

`"Grey": Color8(217, 233, 249, 255),`

`"Brown": Color8(233, 120, 76, 255)}`

var value_to_colors = {

`Color8(235, 52, 96, 255) : "Red",`

`Color8(246, 167, 30, 255) : "Yellow",`

`Color8(42, 177, 196, 255) : "Blue",`

`Color8(52, 64, 106, 255) : "Dark Blue",`

`Color8(176, 209, 56, 255) : "Green",`

`Color8(217, 233, 249, 255) : "Grey",`

`Color8(233, 120, 76, 255) : "Brown"}`

func _on_button_pressed():

`get_tree().change_scene_to_file("res://Factory Scene/Factory.tscn")`

func _ready():

`$Button.text = "Waiting..."`

`world_image = $WorldMap.texture.get_image()`

`default_image = Image.load_from_file("res://WorldPicker/MapWithNoNames.png")`

`height = world_image.get_height()`

`width = world_image.get_width()`

`script_ready = true`



`for child in $WorldMap.get_children():`

	`for second_child : ReferenceRect in child.get_children():`

		`second_child.position = second_child.position / 1.05`

		`second_child.editor_only = true`

func bound_boxes_visibilty(value : bool):

`for child in $WorldMap.get_children():`

	`for second_child : ReferenceRect in child.get_children():`

		`second_child.editor_only = value`

func _process(_delta):

`if script_ready:`

	`var text_value = get_country_behind_mouse()`

	`if is_instance_valid(text_value):`

		`$Button.text = text_value`

func get_country_behind_mouse():

`old_country = new_country`

`var map_mouse_pos = get_global_mouse_position()`

`if map_mouse_pos.x > 0 and width > map_mouse_pos.x and map_mouse_pos.y > 0 and height > map_mouse_pos.y:`

	`var mouse_pixel_color = default_image.get_pixelv(Vector2i(map_mouse_pos))`     

	

	`if mouse_pixel_color in value_to_colors:` 

		`var color = value_to_colors[mouse_pixel_color]`

		

		`for country in get_node(NodePath("WorldMap/" + str(color))).get_children():`

var box_rect = Rect2(country.position, country.size)

if box_rect.has_point(map_mouse_pos) == true:

new_country = country.name

if old_country == new_country:

world_image = default_image

else:

for pixel_x in country.size.x:

for pixel_y in country.size.y:

var border_pixel_location = Vector2i(pixel_x + country.position.x, pixel_y + country.position.y)

var border_pixel_color = default_image.get_pixelv(border_pixel_location)

var border_adjacent_pixels = [default_image.get_pixel(border_pixel_location.x, border_pixel_location.y - 1), # Above

default_image.get_pixel(border_pixel_location.x + 1, border_pixel_location.y), # Right

default_image.get_pixel(border_pixel_location.x, border_pixel_location.y + 1), # Below

default_image.get_pixel(border_pixel_location.x - 1, border_pixel_location.y)] # Left

if border_pixel_color not in value_to_colors:

if colors_to_value[color] in border_adjacent_pixels:

world_image.set_pixelv(border_pixel_location, Color.BLACK)

$WorldMap.texture = ImageTexture.create_from_image(default_image)

if "#" in country.name:

return str(country.name).left(-3)

else:

return str(country.name)

	`else:`

		`return "NO COUNTRY"`

https://reddit.com/link/1gnjdai/video/rjexn4i1txzd1/player

https://reddit.com/link/1gnjdai/video/v7kx8ji1txzd1/player

Dunno why vid is doubled, probably a reddit glitch.

5 Comments
2024/11/09
20:38 UTC

1

Using Godot for water assets vs blender

I have just recently (around a week or more) started learning Godot, Blender and trying Krita.

My game is going to be a simple (in overall mechanics) 3D ship-based combat game, aiming for lower graphical needs (my laptop isn't suitable for gaming or game-making).

I want to use water assets that have, at least decent, wave mechanics, so I checked out blenders ocean modifier, and liked it.

Does this asset work well in Godot?

Since my game is somewhat on the simpler side, I at least want the ship to sway in the waves if they are wild, to add a bit of depth to combat.

Any recommendations on water/waves will be much appreciated, thank you.

(I am not sure if this is an appropriate flair, please give me a heads-up so I can change it)

0 Comments
2024/11/09
20:28 UTC

0

Hi I need help making a decision

https://preview.redd.it/yxi7serunxzd1.png?width=1366&format=png&auto=webp&s=05bdf08ded6bb1a84cfb0f601ff1cc34a4e96c59

https://preview.redd.it/i0fq6erunxzd1.png?width=1366&format=png&auto=webp&s=f9c8dc4e649a8775c2566daace5233d66a7e0b3f

https://preview.redd.it/47edkerunxzd1.png?width=1366&format=png&auto=webp&s=8a43fce8ace4acfe8158921a2c16d1a117cc4ddc

Do you think that with that I can start posting on social media?

The truth is that I feel like it's still lacking, I already have the AI ​​of two enemies, the

weapons, the character control and the story.

The game is like a parody of DOOM and it makes me a bit insecure to start posting and not receive visits.

How do you do with your projects?

Thanks for reading

5 Comments
2024/11/09
20:14 UTC

13

Making open worlds in Godot - is it overtly ambitious?

I know this question comes up a lot, but most of the answers I’ve seen tend to be along the lines of “yes, open worlds are possible, but they’re hard,” without much concrete guidance. So, I'm hoping to get some more practical insights this time

Is Godot genuinely a viable option for creating open-world games, or am I asking too much of the engine for what it currently is? What kind of background knowledge should I be aiming for, and just how challenging is the setup going to be?

Some specific (But not all) questions I have are:

  • Is sticking with GDScript enough or should I learn to utilize C#/C++ and/or bindings?
  • What about working with Godot’s material system for an open-world project? Is it flexible enough, or will I run into limitations?
  • What about asset streaming? How are assets, like meshes and their LODs, as well as textures and their mipmaps stored and streamed? Where can I learn about the more inner workings of these?
  • Just how hard would it be to make tools that'll allow me to sculpt the terrain in-engine?

Basically, I’m trying to understand what’s really required to make an open world work in Godot and whether there are any useful, preferably Godot-specific or engine-agnostic resources to get started on these topics. Any advice or guidance would be hugely appreciated!

5 Comments
2024/11/09
19:24 UTC

6

New class spotlight for the roguelike pirate game we're working on

1 Comment
2024/11/09
19:06 UTC

1

Underwater effect?

How would i create an effect that makes it darker when the player is underwater. So the deeper the player is the darker it gets?

And also ripples:)

1 Comment
2024/11/09
18:50 UTC

3

Having problem with TileSetLayer putting diagonals tiles

1 Comment
2024/11/09
18:39 UTC

43

1-Year Progress on My Tower Defense Roguelike Game

1 Comment
2024/11/09
18:24 UTC

3

using Godot built in script editor for writing C# code

it is possible to use godot script editor for C# ? and if it is possible how i can see the methods of the node like move_and_slide() while writing it ?

6 Comments
2024/11/09
18:23 UTC

2

How to convert vectors to sprites?

Hello all,

I'm a beginner here and probably biting off more than I can chew.

My goal is to draw a vector and then store that vector as a sprite without using a 3rd party application. I'm not interested in creating and importing SVG's nor interested in using aseprite for this process.

My thought process is that maybe I can procedurally generate and animate a vector drawing and then slice, convert to sprite frames, and store them.

Will l have to build my own custom rasterizer? Can I convert the data from polygon to a texture? Should I export the vectors out into a different program?

Any advice is appreciated even if that is: 'keep dreaming'.

Thanks 😊

5 Comments
2024/11/09
18:18 UTC

1

How can I customize/stylize the LineEdit bar and font?

So far, it has the default Godot look like this https://imgur.com/a/Qpv4ptJ

But I wonder if you could change it, like how you can change the scrolling bars or customize texture buttons.

1 Comment
2024/11/09
18:13 UTC

1

How to run C# project from Rider and display remote scene tree in Godot editor?

Hi. I'm evaluating Godot, and I like the combination of GDScript hot reload and remote scene tree editing, especially with the recent 4.4 changes. I'm trying to figure out if it is possible to have a similar experience with C#. Rider 2024.3 RC supports C# hot reload with Godot, but when I run the project using it the editor can't see the remote scene tree or use anything in the debugger panel.

Is there a way to connect the running game to Godot editor to support these things? I tried adding --remote-debug tcp://127.0.0.1:6006 to the run configuration, after which I got a message [DAP] Connection Taken in the editor, but nothing else changed. Thank you!

0 Comments
2024/11/09
18:02 UTC

2

Prototype for a game based on Puss In Boots! Link in comments!

1 Comment
2024/11/09
17:42 UTC

2

Retro FPS tutorial ?

Hello I'm a beginner to godot and I would know what is the best tutorial to make a retro FPS (like doom or quake) ?

1 Comment
2024/11/09
17:42 UTC

1

Connect Godot with Streambot

Hello, very newbie programmer here.
I'm trying to connect Streamerbot with Godot for my live streams on Twitch. I want people to be able to redeem a reward for points (I have it created in Streamerbot and I have its reward ID) so that an animation created in Godot plays. The idea is to use Godot for all these things and free my OBS from so much load. Any ideas or tutorial that explains how to do it or where to look? Thanks in advance.

0 Comments
2024/11/09
16:50 UTC

2

Should my player script be this long?

Hello, everyone. I'm still wrapping my head around the fundamentals here, so this a sort of housekeeping question.

The way I am understanding things, everything that involves the player needs to signal back to the player script.

For example, if I want an area2D to do something when the player enters/exits then that area2D needs to signal those two things which are then coded in the player script.

Over time, with the overwhelming majority of the project scripted in the player script, it becomes understandably quite long. I don't mind a messy sock drawer because it's mine and I know where everything is, but I wonder if this is because I'm making a mistake in my premise with signals. Do I have it right, more or less? Just about everyone's player script is the big script in the project, or am I being inefficient and there's some better way?

8 Comments
2024/11/09
16:47 UTC

2

Re-importing sprites

I have created a sprite with animations in aseprite and my goal is to import that into godot as an animation2d.

I have 2 aseprite importers installed Aseprite Importer and Aseprite Wizard. I have dragged and dropped the ase file into godot, click on import, and reimport as animated2d.

This proces worked perfectly, however, my character animation sprite file is now complete and significantly larger thatn before. When I do the same process, the reimport- bar is stuck at 0% and godot is not responding. This happens with every reimport method I used. The file size is 4mb, which to be honest seems significantly small, for godot not being ebale to handleit(imagine importing 3d sprites). The initial sprite that I managed to reimport was around 250kb.

How do I fix that? Is there a way to make godot handle this process or is there an alternative way to create this animation2d automatically?

I am aware that I can split the file into smaller sections, like for each animation and import it individually, but I want the whole process automated the whole thing to be merged in one single animated2d sprite.

0 Comments
2024/11/09
16:47 UTC

0

Purchase recovery system woes, mobile

Currently using Godot 3.x, will hopefully be upgrading to Godot 4.x soon.

In our game, we have implemented various consumable in-app purchases.

When a user buys an in-app purchase, we register it on our server, linking it to the player's ID. On mobile, we use OS.get_unique_id() as the identifier. This allows us restore consumable purchases, e.g. if the user swaps to an older save or similar. We can check our server to see which purchases this user id should have, and compare it to their save game, and restore the difference. This part works fine.

As noted in the documentation, this ID can change, e.g. if changing phone, uninstalling + reinstalling, etc.

This means that we can have a scenario where a user can, for example, reinstall their game, and end up losing the purchases without being able to recover them.

Without requiring people to create an account specifically for our game, is there any way to improve this from our side? Or do we just need to be clearer on the messaging from our side to minimize the chance of scenarios like this happening?

Since the purchases are consumable, I don't think there's a way to get a history of purchases that include them from the iOS/Android plugins. Likewise, I don't think there is a way to get a more permanent id for purchase tagging.

Are both these assumptions valid?

On Steam, we just use the Steam ID, which works well since that never changes even on reinstall, so ideally something similar to that on iOS + Android would be nice.

0 Comments
2024/11/09
16:35 UTC

17

Adding stairs to my web game was easier than I thought!

14 Comments
2024/11/09
16:26 UTC

1

Topdown AI navigation tips please

I’ve attempted to implement AI navigation for an enemy to pursue the player a few times, but I can’t get it right.

I use a state machine to control the general AI, which I like. I also like the movement of the Boids algorithm for open spaces. But when I put an object between the AI and the player, and I want the enemy to move around the object, have not been able to find a good solution. The enemy usually ends up either getting stuck on a corner or sort of walking in place against the wall.

I’ve tried a few approaches, and have been settling with steering. The steering works ok, but will leave the enemy stuck on larger walls.

So what have you done to make your ai navigation work well?

1 Comment
2024/11/09
16:19 UTC

1

Pause Menu not working

When i click the esc button nothing happens, in the level I have under mode in Process "Pausable" enabled.

Any ideas would definitely be awesome, this is my code below.

extends Control

@export var game_manager : GameManager

# Called when the node enters the scene tree for the first time.

func _ready():

`hide()`

`game_manager.connect("toggle_game_paused", _on_game_manager_toggle_game_paused)`

# Called every frame. 'delta' is the elapsed time since the previous frame.

func _process(delta):

`pass`

func _on_game_manager_toggle_game_paused(is_paused : bool):

`if(is_paused):`

	`show()`

`else:`

	`hide()`

func _on_resume_button_pressed():

`game_manager.game_paused = false`

func _on_exit_button_pressed():

`get_tree().quit()`
0 Comments
2024/11/09
07:16 UTC

1

identifying objects colliding

Hi everyone, Im a newbie.

I wanted to copy a merge game and needed to get the objects name so i can make them disappear and spawn a corresponding new object.

the node tree for each object is really simple, just a rigidbody2d with a sprite2d and a collisionshape2d. the following code is currently attached to the rigidbody2d (the parent)

...

func _get_body_name(body):

if body:

	print (body.name)

	print ("absolutely")

	return body.name

print ("i guess")

func _yes():

print("got the signal")

func _ready():

""""

var collision\_shape = get\_node("CollisionShape")

"""

body\_entered.connect(func():

	print (self.name)

	print ("absolutely")

)

print("got it?")

i left the commenting and also the printing stuffs bc uh, i wanted to show y'all what i've tried. the func in _ready() was originally _get_body_name, but the code didn't run (no errors, just didn't run). i tried replacing with a simpler one just to know if it does get called which was the yes func. still no result. so i tried copying the func down directly but that also didnt work.

i suspect the problem is that the signal doesn't mean the function gets called?? i cant find info on this so please help.

one afternoon ;-; just one afternoon.

thank you for helping

6 Comments
2024/11/09
15:57 UTC

0

Posting before I shelf my idea

As I was working on my game, I realized the scope has gotten out of hand and I have to shelf it for now.

The base is Into the Breach X Final Fantasy Tactcis - You have 3 Main Angels that cannot kill enemies but have cool skills. Under them are soldiers that is AI controlled (but you can influence behavior by training). They can kill enemies.

So the goal is to train them and let them fight for you, using the Angels to save them and largely influence the battlefield.

Story:
The world is nearing its end due to spontaneous arrival of the Nightmares. Made from human imagination and are the common enemies (Sort of like Silent Hill). Nightmares happened as a combination of Dream, Karma, Blasphemy's powers (Bosses to beat). They are in turn here because of Entropy which took advantage of God's oversight. Here God's only power is to create things not control of everything. So he sends the 3 Angels.

Layla (Dark Purple) agressive, mostly hateful against humans because she believes they can be so much more.
Talia (Light Blue) benevolent, often chooses kindness. looks down on humans and pities them thinking they're sad creatures
Eliana (Gold) straightforward, Leader, only cares about the mission. Neutral on humans.
At the core they are the Power Puff Girls setup.

Turns out they can't destroy Nightmares since its technically man-made. And thus the need for soldiers.

I was falling in love with the idea. Thought of Level ups, abilities, customization, battle stages...
But then as I 50 percented the character Layla. I realized that the scope is already far too large, but the idea is far too good (for me) to scope down again.

This is my first game and I know it should be really small. At first this was only meant to be a knockoff Into the Breach. 3 interesting Main OCs, then some shmucks to beat. Save people instead of cities. DONE. But as I worked on it, sadly the "wait a minute..." lightbulb happened.

On the bright side not much is lost, all code is good and i'm gonna reuse the foundation towards a smaller Animal-themed game since they are easier to draw and are interesting by themselves without much context.

Animal Crossing x Into the Breach - Animals trying to save their Village/Kingdom and thats it fr fr

Thanks for reading my Ted Writes.

https://preview.redd.it/vxthwehg9wzd1.png?width=1369&format=png&auto=webp&s=593d4c18ee342ec7ac2311fae878625195db7a80

0 Comments
2024/11/09
15:46 UTC

2

How do I (if possible) add wiggle physics to a Sphere3D?

https://preview.redd.it/qdaxs6631wzd1.jpg?width=1149&format=pjpg&auto=webp&s=aaf459e5076ffa630d89a8dc799a81f8ac1a8e14

I feel this creature could benefit greatly from wiggly eyes. However, I never tried this before, and all the wiggly instruction I've found assumes that you use an imported character with bones.

Can I do wiggly with Sphere3D? If so, what's the node hierachy like?

2 Comments
2024/11/09
14:44 UTC

0

trying to use a var from another scene and it says to me identifier not declared

extends Control

@ onready var var_name = preload("res://scene_name.tscn")

//the space between @ and onready is because reddit is weird

func _ready():

	pass

func _on_start_pressed() -> void:

	if var_name == true:

		$label_name.visible = true

	else:

		get_tree().change_scene_to_file("res://scene_name.tscn")

//(the 2 scenes are the same)

parser error: identifier "var_name" not declared in the current scope.

9 Comments
2024/11/09
14:39 UTC

45

3 Dimensional Maneuver Fishing Rod

11 Comments
2024/11/09
14:24 UTC

10

cats_scene

0 Comments
2024/11/09
14:20 UTC

0

Tips for success using ChatGPT to help with Godot 4.x script, code, dev, design

I replied to another post with this but then decided maybe it needs to be its own post. Feel free to reply with helpful tips of your own! NOTE: this is just for tips that work when asking ChatGPT for Godot project assistance. Please keep your comments on topic so others can get the tips they need!

Best Practices Matter: Always See the Forest for the Trees

[my tips on ChatGPT working for you with GDscript & Godot in general]

My Story: I have learned more about why different code does things, and what it does, and how to do it, in 6 months with chatGPT than in the 4 years prior. Things I can't grasp from the docs, it breaks down in normal language for me. When I forget how to call "not self", it reminds me, and when I want to do something, it gives me a process and a starting point. It even suggests cool stuff I didn't know about and helps me learn those things! That said...

Tip on 4.x code: It wants very much to use Godot 3.x. You can "help it" not do that by reminding it "Godot 4.x only" every so often. One thing that has helped me is just copying a whole section from Godot Docs for latest 4.x (or the link to that page) and giving it to chatGPT (it can read linked urls now). The more I do this, the more it spits out relevant Godot 4.x stuff. Plus, I always paste my working code back in and say this worked: [code stuff] so it learns with me!

No Limits tip: never say "do it this way" unless you are SURE that is the best way (or the only way it can be done in your case). Start with asking for options: What are some options to _______? What would be the most efficient and streamlined ways to _____ considering my end goal is ____? Thoughts? Then ask at least 2 follow up questions to ferret out any reasons why solution x or y would indeed be most appropriate for this case.

The reason is, it often goes down a rabbit hole of doing it "my way" when I was uneducated (or not savvy to, or misinformed) about the best way, I end up with nightmare code and jumbled processes and a day of wasted work.

Is this method correct? Is this code the best solution for your use case?

AKA: Check egos at the door tip ChatGPT comes off as a professional at best, and as VERY egomaniacal and a know-it-all at worst. Once, I replied, "that still won't work bc of x, y, z" and it replied with code it already gave me that didn't work. I said, "why can't you just admit you don't know?" And it froze my chat, threw a red error that I'd reached my limit for today (I'm on paid version, so no limit), and wouldn't let me use the app for a good 4 hours!! THAT is how big its ego is. So, no matter how low quality its answer is, it makes you believe it totally knows what to do in every case. Don't fall for that. Assume there can always be better solutions.

Further, it's a "yes man". So if I say "what about this way?" it blows all kinds of smoke up my $$$ (oh, that's brilliant! What a great idea! That's a fantastic thought [celebration emoji, smiley face], here's how to implement it." If you can, try not to let your ego (or its ego) get in the way of best practices. That's why always giving or asking for 3 options considering your end goal seems to cause it to see the forest for the trees and give actual best processes. It's so easy for me to get bogged down in a detail, so it does too, and I end up having to do it over bc that wasn't even the best way to do it in my case in the first place.

Paste in 'What Works' tip: When it gives you code that works, tell it. Pat it on the AI back. And, paste in any code you got to work that it couldn't with keywords "this worked" (my keyword is 'YAY!' lol). If you know why it worked, add that. Finally paste in all revisions you made. 1) you'll have a record of your process, albeit the ChatGPT search is super lame so I emphasize the keywords highly 2) The more you teach it to do things right, the better it will be for the world and the quicker it will master Godot 3.0-NO. Godot 4.x! Always USE 4.X CODE!!! ;-)

Now, who wouldn't want to help the world??? I sure do. So, at the end of the day, in case you were wondering, I am Xena and ChatGPT is my Gabrielle :D

I hope this helps you in your journey to develop in Godot 4.x and making ChatGPT your trusty sidekick!

11 Comments
2024/11/09
13:55 UTC

350

Finally managed to add AI to my Racing Game 🎉

18 Comments
2024/11/09
13:37 UTC

0

How to FIX this Json saving system on Godot 4.3?

So first I create a text file name SaveData.json
In the Scene1 (that the name of the Scene) script:

func _ready() -> void: #when the scene start
recover()
if scene == 2:
get_tree().change_scene_to_file("res://scene_2.tscn")

var scene = 1
func save():
  var sceneData = {"scene": scene}
  var jsonString = JSON.stringify(sceneData)
  var jsonFile = FileAccess.open("res://Data/SaveData.json", FileAccess.WRITE)
  jsonFile.store_line(jsonString)
  jsonFile.close()
func recover():
  var jsonFile = FileAccess.open("res://Data/SaveData.json", FileAccess.READ)
  var jsonString = jsonFile.get_as_text()
  jsonFile.close()
  var SceneData = JSON.parse_string(jsonString)
  scene = SceneData

func _input(event: InputEvent) -> void: #Where the scene end and start to save
  if Input.is_action_pressed("LMC") :
  anim.play("npc-run")
  await get_tree().create_timer(3.9).timeout
  scene = 2
  save()
  get_tree().change_scene_to_file("res://scene_2.tscn")

So and then I start the project and play the scene to the end. This is what it save in the Json textfile:

{"scene":2}

So and then I start the game again and I thought I would go instantly to scene2 but no this error come up: "Invalid operants ‘Dictionary’ and ‘int’ in operator ‘==’ "
So idk how to fix that.

4 Comments
2024/11/09
13:39 UTC

Back To Top