How do I Correctly Manage Variables

Just started using Construct 2? Post your questions here

Post » Mon Jun 23, 2014 1:49 am

Hello, this is my first post -- I have two days ago installed Construct to try to build myself an application to quiz myself on anagrams. I have gone through the first tutorial and have read much through the examples.

I am discovering that it is most fortunate I have at least a little programming background for what I am trying to accomplish here. Still, it has been a decade since I have done any programming, so this is very new to me. I have a database of words and their anagrams (and sub-anagrams), and will explore some of the json and ajax options with that soon, but for now, I am only trying to get the most basic of functionality.

So far, I have managed to build this quiz, which I just manually put the key word and their anagrams in two global variables, and then check for user input in the TextBox. I first have a section that does the validation that I found in another tutorial.

An event is set for when a user hits 'Return' key to check the entry, and using find() I compare and either append the guess value into a 'correct' text box object or incorrect text box object. Next, I just want to check for duplicate answers, but a question in my mind about best approach here has come up about variable use.

I do not see how to easily set local variables (and should I be using local or global?) . I created the 'guess' variable and assigned it to the textbox in my current project. Is this best practice? How can I see this variables in the Event viewer? I will want to create other variables such as timer and number of guesses. Where should I declare these? (Am I using 'or' logic correctly here? What about if/else? What is the best tutorial to understand logic flow building here?) I don't have objects colliding that cause events, just correct and uncorrect guesses that I want to time and keep track.

I hope my questions are not too vague -- I'm just trying to get a sense for building a word guessing game, and the logic seems more complex than the graphics based game tutorials -- I want to make sure it is easily managed as I continue to work on it, and thus my first question of correct variable use. Many thanks for helping me get started in the right direction.


Screen Shot Image
You do not have the required permissions to view the files attached to this post.
Posts: 86
Reputation: 1,001

Post » Wed Jun 25, 2014 12:42 pm

For your question about local or global variables, I'll invite you to check out the manual article as well as the "Variables (Local/Global/Instances)" section from the "How do I FAQ". The elements listed there should provide answers to your questions.

As for your remark on the graphic versus text logic, it's kind of true.
Game logic is game logic, and it's one of the most difficult aspect of programming no matter what.
Construct 2 provides a better graphic base and is designed to make it easier to handle graphical "behaviors". Nevertheless you can still do text manipulation (as you've found yourself using tokenat). It's a bit more advanced than beginner "platform game making" with C2, but still manageable.

I'd say the next step in your game/program is to take advantage of the dictionary/array so that you can have more words/anagrams available within your game.
Your next step is to "feed" the variables Anagram and Words with datas from one of the two aforementioned plugin.

Keep up the good learning and work.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Posts: 7,333
Reputation: 69,293

Post » Fri Jun 27, 2014 3:39 am

Why dont u use an array to stock all those words?
Posts: 163
Reputation: 2,693

Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests