3D Rad - Free 3D game maker - Forum

This forum is now archived!

This forum is locked, and is a read-only version. A new community-ran forum can be found at classdev.net

News:

The 3DRad community can be found at classdev.net.

Pages: [1]

Author Topic: Cheat codes  (Read 161 times)

« on: June 11, 2014, 05:02:40 PM »
I'm a bit stuck here.
I know it is possible to create a way to do this, but am not sure how exactly.
This is what I have:
Code: [Select]
string Text;
void Main()
{
   if (iInitializing())
   {
      Text = "Type some text...";
   }
   int c = iTypedChar(true);
   if (c > 0)
   {
      Text += " ";
      Text[iStringLen(Text)-1] = c;
   }
   if (c == -2)
   {
      //back-space was pressed
      iStringLeft(Text,Text,iStringLen(Text)-1);
   }
   if (c == -1)
   {
      //enter was pressed
      Text = "";
   }
   if (Text == "tel20")
   {
      iObjectShow(OBJ_22);
   }
   iObjectTextSet(OBJ_0,Text);
}
What I'm trying to do is make it so that when the user types "tel20" to show an object. But, this doesn't seem to work.
Any Ideas?
« Last Edit: June 11, 2014, 05:04:25 PM by NickDH »
« Reply #1 on: June 11, 2014, 05:24:52 PM »
the first thing that i see wrong is that there are no comments in your code...

now i know that you are an expert primo coder who doesn't make mistakes (just like me  ;D ;D ) but coding is easier to do and easier to debug if you write your logic out first as comments...

oh wait... i see some comments  :D

ok, seriously...

you are continually setting the string to "" nothing at the top of the code...

disregard...  looking at it now

you are continually setting the string to "" nothing at the bottom of the code...

here's the logic as comments...

Code: [Select]
   //                       display instructions at initialization

   //                       check for start of typing 
   //                       if typing no longer need instructions get rid of it
   //                       build text from string input and add blank char to end of text
   //                       check for backspace and subtract a char
   //                       check for enter (done entering text)



here's the code written around the (useful) comments...

Code: [Select]

string Text;
bool   alreadyStarted=false;


void Main()
{
   //                       display instructions at initialization
   if (iInitializing())
   {
      Text = "Type some text...";
   }
 
   //                       check for start of typing 
   int c = iTypedChar(true);

   //                       if typing no longer need instructions get rid of it
   if (c > 0)
   {
      if(!alreadyStarted){
        Text="";
        alreadyStarted=true;
      }
   //                       build text from string input and add blank char to end of text
      Text += " ";
      Text[iStringLen(Text)-1] = c;
   }

   //                       check for backspace and subtract a char
   if (c == -2)
   {
      iStringLeft(Text,Text,iStringLen(Text)-1);
   }

   //                      check for enter (done entering text)
   if (c == -1)
   {
     // Text = "";
   }
   if (Text == "tel20")
   {
 //     iObjectShow(OBJ_22);
   }
   iObjectTextSet(OBJ_0,Text);
}


hope this is what you were aiming for... you were almost there...    ;)


--Mike
« Last Edit: June 11, 2014, 05:57:16 PM by Mike Hense »
« Reply #2 on: June 11, 2014, 06:20:58 PM »
and here's a little enhancement...  basically the same logic, but with an underscore used as a visual cue...

Code: [Select]

string Text;
bool   alreadyStarted=false;


void Main()
{
   //                       display instructions
   if (iInitializing())
   {
      Text = "Type some text...";
   }
 
   //                       flag typing 
   int c = iTypedChar(true);

   //                       if typing no longer need instructions
   if (c > 0)
   {
      if(!alreadyStarted){
        Text="";
        alreadyStarted=true;
      }
   
     iStringLeft(Text,Text,iStringLen(Text)-2);
      //                       add blank char to end of text
      Text += " ";
      Text[iStringLen(Text)-1] = c;
      //                       add an underscore as a visual cue
      Text+="_ ";     
   }

   //                       check for backspace
   if (c == -2)
   {
      //                    delete 3 chars back (underscore plus deleted plus extra space)
      iStringLeft(Text,Text,iStringLen(Text)-3);
      Text+="_ ";
   }

   //                      check for enter (done entering text) if done remove underscore
   if (c == -1)
   {
     iStringLeft(Text,Text,iStringLen(Text)-2);
   }
   if (Text == "tel20")
   {
 //     iObjectShow(OBJ_22);
   }
   iObjectTextSet(OBJ_0,Text);
}


--Mike
« Reply #3 on: June 11, 2014, 06:29:00 PM »
Hi Mike
Thank you a ton. I suppose I comments to help a lot  ;D
« Reply #4 on: June 11, 2014, 06:37:20 PM »
you're quite welcome...

you know what you're doing... you've got the coding down pat... and your code looks like it's based on sound logic...

it's just that i find it better to write the logic out first... simply, in plain english...  just what i'd like to do (with regard to what the computer can do)... then write the code to follow it (with regard to what 3DRAD can do)...

its usually easier to look at plain english comments and see where the logic fails... fix that then write the code... it'll come easier than if you try to do it without any guidance...

just a suggestion...  good luck with your project...


--Mike


« Reply #5 on: June 12, 2014, 05:29:55 PM »
here's the project we were messaging about... you should be able to get everything you want from it...

check it out cause i just whipped it together in a few minutes...
you can enter multiple entries....

no error checking for bad coords... i think they'll be set to zero...


cost- 10% of your first million   ;D

--Mike
« Last Edit: June 12, 2014, 05:35:05 PM by Mike Hense »
« Reply #6 on: June 12, 2014, 07:10:29 PM »
here's the project we were messaging about... you should be able to get everything you want from it...

check it out cause i just whipped it together in a few minutes...
you can enter multiple entries....

no error checking for bad coords... i think they'll be set to zero...


cost- 10% of your first million   ;D

--Mike

Can't do that, how about a 30 years supply worth of cookies?  ;D
Thanks a ton Mike!
« Reply #7 on: June 13, 2014, 10:41:28 AM »
i can't take the cookies... i'm addicted to sweets... it'd kill me  ;D


i noticed 5  downloads... for all you others  looking at this, the user can enter a command in the text... the only one it is set up for is /loc  which sets the new location for the fish object...

--Mike
« Reply #8 on: June 14, 2014, 09:27:50 AM »
this is starting to turn into a lesson, so i'm lets post Q&A  on the forum... easier for me to follow... and maybe some others might benefit as well (i see a few downloads)...


you're not gonna understand the code right away... it takes me a lil time to understand other people's code when i look at it... THAT IS WHY WE HAVE COMMENTS...

ok... first look at the Main() section... this is where everything is happens...

as you can see, this part is extremely simple... it just calls GetInput()... this is a function, that is coded below, outside of Main()... so, there's really nothing to do here... lets look below and find GetInput()...


this does everything necessary to get the user input, like the name implies...  that's all it does...  so you really don't need to do anything here either... but if you look at the nottom of the code, you can see this function calls another function... ValidateCmd()... so, lets look up at that function...

look for a comment where the logic looks to check to see if /loc is entered...

when you find it you see that here is where it sets the cmdID to 1... this is the place where you'd want to add checks for other cmds...

use the say format and add 
Code: [Select]
   if(strLeft4=="/res")cmdID=2;
now the logic can check for 2 things...

now, if you continue down, you see the comments for each section of code shows that the code is just checking to see what cmd is being entered...  if cmdID==0 then no command has been entered and the code will exit the function here..

if cmdID==1 then the command is Locate, and it will trickle down and execute the rest of the commands... 

since you want to add more commands, it is gonna be necessary to group this section of code into its own block...  this is done by adding an open bracket at the top (end of the if question)  and at the end and indenting everything in between (for readability only)... like below...

Code: [Select]
   if(cmdID==1){
 
     //                      check for first set of valid X coord numbers
     int n;

     for(n=6; n< iStringLen(Text);n++){
       iStringMid(strTest, Text,n,1);
       if(strTest==" ") break;
       strX+=strTest;
       //                      debug value printout
       iObjectTextSet(OBJ_44,strX + "####");
     }

     //                      get ready to check for valid Y coord
     strTest="";
     strY="";
     int   lastBreak=n;

     //                      check for 2nd set of valid numbers for Y coord   
     for(n=lastBreak+1; n< iStringLen(Text);n++){
       iStringMid(strTest, Text,n,1);
       if(strTest==" ") break;
       strY+=strTest;
       //                      debug value printout
       iObjectTextSet(OBJ_66,strY + "####");
     }

     //                      get ready to check for valid Z coord
     strTest="";
     strZ="";
     lastBreak=n;

     //                      check for 3rd set of valid numbers for Z coord
     for(n=lastBreak+1; n< iStringLen(Text);n++){
       iStringMid(strTest, Text,n,1);
       if(strTest==" ") break;
       strZ+=strTest;
       //                      debug value printout
      iObjectTextSet(OBJ_88,strZ + "####");
     }
 
   
     if(isDone==false){
       iStringLeft(Text,Text,iStringLen(Text)-1);
       isDone=true;
       //                   place the object at location
       iObjectLocationSet(OBJ_110,Vector3(int(iStringVal(strX)), iStringVal(strY), iStringVal(strZ)));
     }
 
  }

this should help you make sense of what's going on, and clue you in to what to do next...

you've added a new command... now, what code do you think you need to add and where do you think you need to add it... 


--Mike
« Last Edit: June 14, 2014, 09:32:57 AM by Mike Hense »
Pages: [1]