|
Post by nazari on Apr 10, 2015 19:52:19 GMT
Hi, please im trying to watch what is in my file bud this dont work
if(inputText== "A"||"B"){
return true;
}
i dont know why , insted im using this long way :-\
if(inputText== "A"){return true;}
if(inputText== "B"){return true;}
if(inputText== "C"){return true;}
... else return false
is there any way , i can still use first example?
|
|
|
Post by Power Supersport on Apr 10, 2015 20:20:07 GMT
What I can offer is that:
if ((inputText == "A") or (inputText == "B") or (inputText == "C")) {return true;} else {return false;} Based on my coding experience I only use examples like this... I don't know any other way...
|
|
|
Post by nazari on Apr 10, 2015 20:25:38 GMT
is there any SWICH thing as example pls?
|
|
|
Post by Power Supersport on Apr 10, 2015 20:32:10 GMT
I should try, but later... maybe tomorrow...
|
|
|
Post by mikehense on Apr 10, 2015 23:42:33 GMT
// switch/case conditional statements
// work with integers,not strings
// so i used a function for the keypress
// which returns a numeric ASCII value
//
//
int inputText;
void Main() // the below this comments is the logic
{
if(iTypedChar(false)!=0){ // if a key was pressed inputText=iTypedChar(true);
switch (inputText){ // test with switch/case for
case 65 : // cap A pressed iObjectTextSet(OBJ_0,"A was entered"); // set the text object break;
case 97: // lower A pressed iObjectTextSet(OBJ_0,"A was entered"); // set the text object break;
case 66: // cap B pressed iObjectTextSet(OBJ_0,"B was entered"); // set the text object break;
case 98: // lower B pressed iObjectTextSet(OBJ_0,"B was entered"); // set the text object break;
}
} else { // else iObjectTextSet(OBJ_0,""); // clear the text object }
}
i'd suggest using the if/else logic because it avoids the necessity of converting to integers, and simpler testing for upper or lower case...
--Mike
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Apr 11, 2015 8:33:07 GMT
but sometimes the switch feature makes the scripting less complicated than the if-if-else.
|
|
|
Post by F1Andre on Apr 11, 2015 9:39:17 GMT
I like Mike's idea, however when you work with something like this I always like to make a small algorithm, it will take about 100||150 lines. It kind of brings me back to my Java days with all the algorithms needed to solve the mathematical equations. Plus if you practice the long hard way you will improve your skills and prepare yourself for when you move to advanced programs or if you for some odd reason leave game development for software development. Try to avoid Hard-Coding, it will become a habit!
|
|
|
Post by F1Andre on Apr 11, 2015 10:22:52 GMT
I had a look at your question again, in the end you would wind up with the same amount of lines. It just comes down to maintaining the code and writing it efficiently. You must write the code in such a way that you feel comfortable maintaining and reading it. If you try the hard way and it works but you struggle to maintain and use the code, ditch the code or put it in /* */ these and replace the code with what you feel most comfortable with. Any fool can write code that a computer can understand. Good programmers write code that humans can understand - Martin Fowler
|
|
|
Post by nazari on Apr 12, 2015 12:43:18 GMT
Thank you guys, u helped me a lot, soon i will upload my little navigation game
|
|
|
Post by F1Andre on Apr 12, 2015 15:53:10 GMT
It's our pleasure, we hope to see your game soon.
|
|