Answer Control for Word Game

Hello everyone. I have a problem. I making a word game as follows. the cells are seperately and i wrote an answer control but when i put first letter to first cell, printing continuously because of update function. I wrote bool variable but didn’t work again, even used comp = !comp. I think i did wrong. I tried can you help for this?


public bool comp = false;
    public float timer;
    public GameObject[] tumHucreler;
    public string cevap;

    void Update(){
        if (!comp) {
            for (int x = 0; x < tumHucreler.Length && comp; x++) {
                if (tumHucreler [x].transform.GetChild (0) != null) {
                    cevap += tumHucreler [x].transform.GetChild (0).name;
                    comp = true;
                }
            }
        }
    }

I don’t completely understand the issue. Maybe I do…

In any event, what I think you’d “appreciate” is to move this “puzzle check” somewhere that you can call (that occurs) after a puzzle piece is placed (or moved). There is really no need for the Update() loop here.

Do users drag the items or type ? Either way, when something is dragged or typed, you can check if the letters are in the correct order at that time. :slight_smile:

Users will drag letters to cells and if letter sequence is correct(e.g. DUCK as in the screenshot), level will complete. but when i drag and drop first letter to first cell, printing continuously for example drag and drop D, printing D forever. i wrote bool function but it did only once

Right… so we could fix that … obviously that’s an option.
What I’m suggesting, however, is that when the letter is dropped (or moved , if you can swap positions, for instance), you then run the “Check for correct answer” method…
It’s more practical, better performance, and will eliminate your ‘bug’ as a bonus :wink:

I’m a little confused why you would not want to “fix it” by the means I suggested…?

Sorry. I was going to write another answer. Sorry It was a mistake.

Just to be clear – does that mean you’re going to try the option I suggested? :slight_smile:

Yes. No harm comes from trying.

Cool… ya. I mean, it will essentially turn into almost exactly the same thing as having a bool in update on/off.
If they haven’t moved a letter into place, there’s no need to check, right? It can’t possibly be done… so may as well run the “check” when something has changed.
Anyhow, good luck with your game :slight_smile:

same thing with my opinion already. actually i thought when i drag D bool true, dragging U false, dragging C true, dragging K false. So every time I put one true one false go on. is not it?

I could extend my response to say, only when all 4 are in place (or moved) then do the check. :slight_smile:

Either way, for a few letters, it really doesn’t matter much.

What I was saying about your update method and bool was this:
if you set the bool true after you drop something… thereby letting update run its check, and afterwards the bool is set to false to prevent further runs… You’ve effectively just created a “method of sorts” via the Update() method (/loop). May as well just call a method to do your check instead of even caring about the bool in the first place…In any event, as I’m repeating myself here, it seems…
I’m off for now, but hopefully you can get it working. :slight_smile:

OK. Thanks for help

Okay, np. Write back if you get it to work :slight_smile:

I made it. I can controlling answer. when the answer get wrong, debug warns you wrong but I put the item back being nothing. if the cells will be empty, bool will get false. I couldn’t. I don’t know put where it is. I placed else parts but didn’t work.

public bool comp = false;
    public GameObject[] tumHucreler;
    public string result;
    public string answer;

    void Update(){
        if (!comp) {
            for (int x = 0; x < tumHucreler.Length; x++) {
                if (tumHucreler [tumHucreler.Length - 1].transform.GetChild (0) != null) {
                    result += tumHucreler [x].transform.GetChild (0).name;
                    comp = true;
                }
            }
        } else {
            if (result == answer)
                Debug.Log ("Correct");
            else{
                Debug.Log ("Wrong");
                result = "";
            }
        }

    }

I see you left in the update function after all.
If I’m understanding correctly, you’re setting ‘comp’ to false when you drag/drop a letter, correct?

you should move : “comp = true” outside of the loop.
And right under “if (!comp) {”
you should have : result = “”; this will just empty it out from the last ‘try’. otherwise you’ll get like: dkuckdukdcuk out of order letters trying to spell duck.

Then, I’m not sure why you’re trying to test if the last entry is valid, but if you want to do that, you could just test them all if they’re valid before you compare at all. Maybe you meant to be testing the index of ‘x’ in the loop, instead?

the script not controlling only last entry. when last a letter placed to last cell, result will appear and it will compare answer and result. that’s it. I will make a reset button already. i’ll press reset button and the all cells will be automatically empty not drag and drop. then the bool will be false and user will try again.

Okay, perhaps there is a communication/language issue between us. At this point, I’m unsure what is working and what is not… Sorry.

My english is a little bad. Sometimes I can not understand you either. You are right about this. I am sorry too. Anyway. there will be a reset button and when i press, cells will be empty and comp bool will be false. that’s it

I wish I could help more…Is anything I said before or recently made sense to you?

No. I have only wrong part. I couldn’t make comp bool false