#Snake, how do i add segments?

1 messages · Page 2 of 1

random wasp
#

oh ok

wooden maple
#

A signal tutorial will help you

random wasp
#

i think i should watch one and then get back?

wooden maple
#

But honestly, the growth delay doesn't seem like a big deal

wooden maple
#

The signal thing is just to fix the growth delay

random wasp
#

well if youre really big it kinda is

wooden maple
#

Oh wait, that's the problem you were describing in the first place llmao

random wasp
#

nonono

#

two problems

#

one i dont really care actually

#

and one its kinda important

#

first one is the little extra time it takes for a segment to die, which i dont care

#

and the other is the long time it takes for the new segment to appear if youre big

wooden maple
random wasp
#

uhm

#

no

wooden maple
#

elaborate

random wasp
#

it because

#

suppose

#

you eat an apple at 10, 10

#

a segment is spawned at 10, 10

#

that segment will only be visible when theres NOT another segment at 10, 10

#

which takes a while if youre big

wooden maple
#

The segment at 10,10 will be visible when there's not a segment at 10,10

#

?

#

Oh

#

Let me ask this

#

You eat the apple at 10, 10

#

Do 30 frames pass between then and when you create a new segment?

random wasp
#

sorry the 30 frames is just an imaginary number for example?

wooden maple
#

yeah, that's like, movespeed

random wasp
#

ok, no, when you eat the apple the new segment gets created instantly

#

oh i saw the problem wrongly

#

you saw it correctly

wooden maple
#

Yeah, there's no reason to do that

#

Just only create segments when you move

#

So that there aren't overlapping segments in the first place

wooden maple
#

yeyeyeyeyeyey

random wasp
#

yes there arent*]

wooden maple
#

:o

random wasp
#

so instead of changing death timer for the next segment it should change for all the segments death timers?

wooden maple
#

I don't understand what the problem is anymore

random wasp
#

arrgh

#

is there a built in windows screen recorder?

#

dont wanna download obs

wooden maple
#

iunno

#

I just use obs lol

#

Describe everything that happens in steps

#

you move, you eat the apple

#

then what

random wasp
#

ok

#

lets say you only move in 1 dimention so its easier to visualize

#

lets say you also need 1 second to move

wooden maple
#

k

random wasp
#

lets say youre at 5 (position in 1d space)

#

apple at 10

wooden maple
#

yeah

random wasp
#

you have score 5 which means theres 5 segments + the head

wooden maple
#

each segment's timer is set to 5 seconds when it spawns

#

ye?

random wasp
#

last segment at 0 and you at 5

random wasp
wooden maple
#

okedoke

random wasp
#

you move to six

#

all the segments lose 1 second of their life

#

segment at 0 dies

#

that continues, when you eat the apple instead of having 5 segments you have 6

wooden maple
#

????

random wasp
#

everytime you eat an apple you grow

wooden maple
#

Where do you grow

random wasp
#

well yeah thats fair

#

should be using technical talk

wooden maple
#

nonono go back to 9

random wasp
#

okay

wooden maple
#

the head is at 9

random wasp
#

yes

wooden maple
#

segments on 8,7,6,5,4

random wasp
#

yep

wooden maple
#

continue

random wasp
#

okay

#

so you eat the apple :o

wooden maple
#

you move

#

then eat the apple

random wasp
#

so theres a segment at 9,8,7,6,5

#

and the head at 10

wooden maple
#

ye

random wasp
#

then the head moves again, to 11, but instead of making all the segments 9,8,7,6,5 gain +1 seconds on their life only the segment created on 10 has +1 second, so in the same tick segment at 5 dies instead of living for 1 more second

wooden maple
#

So you have segments on 10,9,8,7,6

random wasp
#

yes

#

and you still visualy have 5 segments

#

BUT

#

the times look like this:
10: 6
9: 4
8: 3
7: 2
6: 1
5: dead

#

so you visually have 5 segments

#

next tick:
11: 6
10: 5
9: 3
8: 2
7: 1
6: dead
still visually 5 segments

#

12: 6
11: 5
10: 4
9: 2
8: 1
7: dead
5 visual segments

#

13: 6
12: 5
11: 4
10: 3
9: 1
8: dead
5 visual segments

#

14: 6
13: 5
12: 4
11: 3
10: 2
9: dead
5 visual segments

#

only NOW

#

15: 6
14: 5
13: 4
12: 3
11: 2
10: 1
now theres 6 visual segments

wooden maple
#

yeah, makes sense

random wasp
#

it took x seconds for x ammount of segments for it to make a visual difference

wooden maple
#

Not a glitch, but I can see how that might be undesirable

random wasp
#

yes, not a glitch

#

understanding the error fully now makes it more easibly understandable

wooden maple
#

Show me where you're increasing the score

random wasp
#

still dont quite know how to fix

random wasp
wooden maple
#

Perfect, that makes this easier

random wasp
#

oh i think we didnt talk about that call deferred right?

wooden maple
#

lol what is call_deferred

random wasp
#

used a little bit of chat gpt, for some reason the function add segment and start death timer werent working inside the function eaten apple

#

call deferred makes x function execute instantly when declared

random wasp
wooden maple
#

That's how functions usually work

#

Oh

#

Depends on how you're using declared

#

I forget what that means in coding

random wasp
#

fixed it lol

wooden maple
#

This is wild because your start death timer function should be causing errors

random wasp
#

add segment and start death timer where below eaten apple

#

i dont think so

wooden maple
#

Oh, cause you're declaring segment at the top?

random wasp
#

i am

wooden maple
#

okedoke

random wasp
#

uhmm

#

logically something like

#

you add 1 second to all the segment timers when you eat an apple

wooden maple
#

Ok, so timers and buttons both use signals

#

You have a timer, it goes off, it sends a signal to the thing it's attached to to do something

#

You have a button, player clicks it, it sends a signal to whatever it should to do some stuff

random wasp
#

maybe like this?

wooden maple
#

You should not add a segment when you eat an apple

random wasp
wooden maple
#

You add segments when you move

#

You might also just put _start_death_timer() inside _add_segment()

random wasp
wooden maple
#

because you start the death timer when you add the segment

random wasp
#

ok got overwhelmed

#

first thing

#

remembered why i used call deferred

#

because this error shows up otherwise: (although it still works)

#

secondly eating apple should just change the death timer if i understood it?

wooden maple
#

Yeah, with a signal, but we're not quite there yet

random wasp
#

wanna see the codes?

wooden maple
wooden maple
random wasp
wooden maple
#

Ok cool, probably purge 25 and 26 from the face of this earth

#

Then watch a tutorial on signals

#

I think the gist is that you create a signal at the top,
connect the signal to each segment you create,
write a function inside segment to add time to it's death timer
signal_name.emit() inside _apple_eaten()

#

I don't remember how to connect signals

#

But the tutorial will prolly tell you all about it

random wasp
#

ok, wanna continue tomorrow?

wooden maple
#

You should be good from here

#

There's a p good main menu tutorial I can send

random wasp
#

k, getting kinda sleepy now

wooden maple
#

ok nigh nigh

random wasp
#

GINORMOUS GIGANTIC BIG STRONDOWS EPILEPTIC thank you, bro you putting so many lumps in my smooth brain

wooden maple
#

yah

random wasp
#

im remaking the game and its now so much clearer

#

so much cleaner

random wasp
#

@wooden maple BROOOO I MAY ACTUALLY HAVE DONE IT DID DADTADDI DONT KNOW GRAMMAR

#

the visual ammount of segments get changed the next tick after eating an apple, i even felt a cool in my body when i did it, it does though kinda glitch after but stabilizes im gonna record a video and show

random wasp
wooden maple
#

Congrats man!

#

make sure to mark this post as solved

random wasp
#

not solved

#

have you not seen the video?

random wasp
#

@wooden maple please i have no idea why this is happening

wooden maple
#

Oh my bad

random wasp
#

help please 😭

random wasp
#

ARHH I THINK ID IDIDID IT

#

i aisdoasd cant even describe how, i put the death_timer definitions and changes all of them inside segment.gd instead of the head.gd

#

i think, its the last step

#

body collision