Interact with variables of other scripts in my project

Hi

I’ve been stucked in my project for few days because I couldn’t understand how to reach variables in others scripts
I made a thread about it, it teached me interesting things, but I’m still stucked…
That’s why I make a new one where I directly speak of my project

5616544--582103--upload_2020-3-22_16-32-56.png
So, as you see I’ve made a checkerboard where I can put pawns (which actually are numbers) into cases (if you see what I mean)

I have 2 problems :

First :
I can’t forbid a pawn to go into a case when it’s already filled with another pawn
I tried to create a variable for each case; when a pawn goes into one, it’s value becomes 1 and for the others pawns it is impossible to go into a case whose value is 1
I wanted to store those variables into an other script because it didn’t work if I was doing it in the pawn’s script (the value was changing just for the pawn filled in the case, even though I set it public)
But how can I do that ? I didn’t understand how to use the get/set thing I saw elsewhere and if that was what I needed for my problem
I want it:

  • Create the variables in a second script (the ones that says if the case if filled or not)
  • When a pawn enters a case, which happens in the first script, it modify the second script’s variable and set it to 1
  • If another pawn want to enter in case already filled, it consults the variable in the second script : =1 ? it’s ok can fill the case, !=1 ? go back to it’s original position

Do you need to see the first script ?

So that was the first problem and the most important one (if you’re too lazy to answer all my problems, which I actually totally understand ^^, please just help me with this one…)

The second one is just more optionnal, if you have time to think about it with me…
I would like to calculate for each columns, lines and diagonals of the checkerboard the sum of the values of the pawns therein
I think the solution would be to create a script per column, line and diagonal : when a pawn enters a case, that case increases the value of the variable of the scripts which represent the diagonal, line and culumn where it is (I’m not a english native speaker, I hope you understood ^^)
And at the end those scripts send their values to a final one which compare them…
I don’t know if it’s feasible and most of all how to program it ^^
Now you understand how much I need to understand how to interact with variables of other scripts

Thank you so much for reading my post !

Problem 1:
Should be really easy to solve. Please just paste in your code that handles the actual placement of the pawns on the table. I don’t know how you store these fields, do you maybe store a matrix? Maybe you just click on a pawn and then click on a field? Anyhow, please post that and it shouldn’t be hard to answer your question from there.

Problem 2:
Also not difficult (so don’t give up if it seems hard at first). You’ll want to look at matrixes. In your scenario, you have a grid of 5x4. Each element in that grid is one field. Every element can be filled with any data, so you can store the values of the pawns and even if the spot has been filled with another pawn (which solves your first problem). It also makes all the calculations you mentioned quite possible.