#lets make a thread, and send both script

1 messages · Page 1 of 1 (latest)

fading granite
#

I will change the .name.equals player later

#

i just want the white square system to work

summer isle
#

which object has which script btw

#

also not very good doing this in update cs void Update() { currentHeldRedSquare.transform.localPosition = Vector3.zero; }

fading granite
#

every red square has their own GrabScript and every white square has a blockplacescript

summer isle
#

just parent it

wanton night
#

looks like both updates are overwriting values of one transform

fading granite
#

well i want the transform position to be equal to the grabposition if it is being picked up

#

and i want the transform position to be equal to the white square

#

position if it touches the white square

summer isle
#

it should work

#

make sure that method is running

fading granite
#

which lines

#
public class WhiteSquare : MonoBehaviour
{
    private RedSquare currentHeldRedSquare;
    public void TrySetHeld(RedSquare sq)
    {
        if (currentHeldRedSquare!= null) return;
        currentHeldRedSquare= sq;
    }
}
public class RedSquare : MonoBehaviour
{
    public void OnTriggerEnter2D(Collider2D other)
    {
        if (other.TryGetComponent(out WhiteSquare white))
        {
            white.TrySetHeld(this);
        }
    }
}
#

these?

summer isle
# fading granite which lines
 public void TrySetHeld(RedSquare sq)
 {
     Debug.Log("Trying to set square" + sq.name);
     if (CurrentHeldRedSquare != null) return;
     CurrentHeldRedSquare = sq;
     CurrentHeldRedSquare.transform.position = transform.position;
 }```
fading granite
#
public void TrySetHeld(GrabScript sq)
    {
        Debug.Log("Trying to set square" + sq.name);
        if (currentHeldRedSquare != null) return;
        currentHeldRedSquare = sq;
        currentHeldRedSquare.transform.position = transform.position;
    }
#

modification is good or no?

summer isle
#

put another at bottom just for good measure

fading granite
#

another how?

#

like paste it again?

summer isle
#

Debug.Log($"Added {sq.name}!");

#

at bottom

fading granite
#

like this?

summer isle
#

yes

#

get rid of that line of Update

#

if currentHeldSquare was null you get spammed with error

fading granite
#

now its this

summer isle
#

yea

#

so is it printing ingame ?

fading granite
#

im gonna look what happens

#

Well what happens is

#

the picking up and placing still works

#

when i hover over a white square with the red square it says its added the square but it didnt actually move it because i have it on my grabposition

#

i need to release the block first i think

#

@summer isle ok im making good progress

summer isle
fading granite
#

by making it so it releases the block using the Release() function i make it go into the white square

summer isle
#

the other one was cluttered i didnt noticed it was overwritten

fading granite
#

i can now also pick it up again, but

#

i cant put it back in

summer isle
#

yes because you still need to clean it up

#

now that BlockPlaceScript has its own method to Try to place down

#

now you need same thing for retrieval

fading granite
#

in the blockplacescript or the grabscript?

summer isle
#

how do you want the red to be picked up

#

if player collides into it ?

fading granite
#

no

#

using e to pick it up like normal

#

that works fine, but the whitesquare still thinks it has a block inside

summer isle
#

but what determines that you are able to pickup

fading granite
#

when it hasnt

summer isle
#

iknow what the problem is

fading granite
#

the top part

summer isle
#

but how do you find that particular red square

fading granite
#

if it triggers

#

PickupAllowed will be true if the block is touching the player and if the player is not holding anything

summer isle
#

ahh this is on the red square?

fading granite
#

yes

summer isle
#

you should have a slot on the player to check

fading granite
#

what do you mean?

summer isle
#

but also you need a way to tell the whitesquare that you got picked up

#

GrabScript is the red square?

fading granite
#

yes

summer isle
#

eh confusing naming scheme also red square does wayy too much

#

this should only be in the player

fading granite
#

Yeah, that was my bad

summer isle
#

but anyway if player had GrabScript redSquare slot for example

#

so you can actually determine the thing you're holding if its null or not

#

what you can do is make a slot for whitesquare in red square maybe

#

thats one way to do it

#

private BlockPlaceScript currentParent;

fading granite
#

like

private BlockPlaceScript whiteSquare;
summer isle
#

yea

fading granite
#

ok

summer isle
#

the same thing you do for TrySetHeld

#

but for GrabScript

fading granite
#

So Retrieve(); or something

#

so the whitesquare script will set the currentredsquare to null

summer isle
#

public void TrySetHeld(GrabScript sq)
{
if (currentHeldRedSquare!= null) return;
currentHeldRedSquare= sq;
currentHeldRedSquare.SetWhiteSquare(this)
}

#

then you can call that same method but set it to Null on pickup

#
 private void PickUp()
    {
        movementScript.holding = true;
        holding = true;
          if(whiteSquare != null) whiteSquare.SetWhiteSquare(null);
    }```
fading granite
#

public void SetWhiteSquare(BlockPlaceScript ws)
{
if (whiteSquare = null) return;
whiteSquare = null;
}

#

i did this, but i think its way wrong

#

should the SetWhiteSquare() be in the whitesquare script or the red square

summer isle
#

RedSquare

#

you're saying this is who i belong to

fading granite
#

but the pickupscript is already in the redsquare

#

private void PickUp()
{
movementScript.holding = true;
holding = true;
if(whiteSquare != null) whiteSquare.SetWhiteSquare(null);
}

#

this one

summer isle
#

wait yeah

fading granite
#

and the whiteSquare.SetWhiteSquare should be in the white script then, but how do i make it in the red square

summer isle
#

hold on

#

your naming classes confused myself

#

one sec

fading granite
#

sorry about that

#

It was first just a test on picking up blocks, then i wanted to expand and add these white things

summer isle
#

all good, just needs a bit of refactor so its less confusing

#

give me 5 mins brb

fading granite
#

alr

#

Update: I have been able to make the blocks go into the white squares as i wanted to

#

i have also been able to make it so i can pick up the block, but now there is the issue again where i can place multiple blocks in one white square

#

So i am going to try and fix that now

#

This one is in the Redsquare script

#

this one in the white square script

#

This one is also in the red square script

summer isle
#

send updated scripts in link

fading granite
#

first is white square, second red square

summer isle
#

currentHeldRedSquare.Release(); inside TrySetHeld

fading granite
#

So the player releases the block, if the block isnt released it will just be held by the player

#

by making position equal to grabposition

summer isle
#

if (currentHeldRedSquare != null) return; this would keep anything below to run if you try to place block on white that has red

#

your must've override or done something to do so somewhere

fading granite
#

im confused sorry

#

i have done some tests

#

and sometimes it just does the things below cs if (currentHeldRedSquare != null) return; even if currentHeldSquare != null

summer isle
#

you have to find out why currentHeldSquare is null for some reason

fading granite
#

no but it isnt, because i have a public bool in game so i can see if it is null or not

#

and when i do the test it says it isnt null

summer isle
#

prob your old code part

fading granite
#

i tried to send a video

#

of what i mean

#

you dont have to download it if you dont want to

#

should i make another yt link?

summer isle
fading granite
#

There is a loud dc notification sound in the vid just saying

#

0:24

summer isle
#

hmm I see

fading granite
#
void Update()
    {
        if(currentHeldRedSquare != null)
        {
            holding = true;
        }
        else
        {
            holding = false;
        }
    }
summer isle
#

I see 2 nested blocplace

fading granite
#

sorry?

summer isle
#

maybe there is another script on parent ?

fading granite
#

no

#

the empty gameobject just has a transform

#

The debug.log shouldnt say Added if the holding is true

#

cus if the holding is true that means that currentHeldRedSquare != null

summer isle
#

yeah

fading granite
#
public void TrySetHeld(GrabScript sq)
    {
        Debug.Log("Trying to set square" + sq.name);
        if (currentHeldRedSquare != null) return;
        currentHeldRedSquare = sq;
        currentHeldRedSquare.Release();
        currentHeldRedSquare.transform.position = transform.position;
        Debug.Log($"Added {sq.name}!");
    } 
#

and then it just returns

summer isle
#

something obvious im not noticing

fading granite
#

Actual Question: Do you find it fun to help me with my project?

summer isle
#

prob because im at work haha

fading granite
#

lol

#

its 22:03 here so im at home

summer isle
#

in spare time

fading granite
#

cool

summer isle
#

im just at work but I get out in a half hr so ill be fully focus mode haha

summer isle
fading granite
#

lol

#

it prob has to do with there being more than 1 white squares

#

or no?

#

what if i say whiteSquare = null when i pickup

#
private void PickUp()
    {
        movementScript.holding = true;
        holding = true;
        if (whiteSquare != null) 
        
        {
         whiteSquare.ClearWhiteSquare();
         whiteSquare = null;
        } 
    }
#

i added the Whitesquare = null line

#

Omg

#

it almost works perfectly

#

on some weird moments it still takes 2 blocks in one white square

#

What if i just continue with my game idea with this just being a bug that i can fix later

#

or should i really fix it now?

summer isle
#

should fix it now

fading granite
#

Im stuck

#

im gonna fix it later and im gonna take a break

#

Thanks a lot for the help today, i really appreciate it!

summer isle
#

no problem Ill try to send some ideas how to fix in a bit