Console Question

Blitz3D Forums/Blitz3D Programming/Console Question

Conan(Posted 2004) [#1]
Hey, i'm doing this game, and i figured it'd be a lot easier to modify it form inside the game, so i thought i'd build a console into it... and i made a complete fiasco. Does someon know how to make a console work out in a 3d game (preferably with a hide/show console thing)


jfk EO-11110(Posted 2004) [#2]
probably you should collect all Keystrokes by using inkeys$ at the end of the loop, filter them and add all legal characters to a virtual input-string until the user hits enter. Then you'd interpret this string. Meanwhile all you have to do is to write the string to the screen corner.

This method allows to navigate/play and use the console at the same time and won't pause the game when you want to enter something.


Conan(Posted 2004) [#3]
geez, sounds so easy... thanks, man...


BlackD(Posted 2004) [#4]
ok.. want an example? :)

http://blitz.geek.nz/test.zip

This is a WORKING example from a program I'm writing at the moment, source included. The main two features which are what you will need to incorporate:
- The drop-down console.. its very customised for exactly what I want, but reading console.bb will give you a clear hint of how it all works.
- A CVAR system. You'll need to write your program using a CVAR system if you want to be able to change values via a console. (Unless you want to write a function for every possible console command).

For the CVAR system, read CVAR.BB to see how the cvar's are created, and the CVAR routine at the bottom of FUNCTIONS.BB.

With CVARs (Custom VARiables), you'll need to write changes to the code to reflect it.. so rather than having:
LightColor Light,Red,Green,Blue
you'd have
LightColor Light,Cvar("red"),Cvar("green"),Cvar("blue")
and you'd be able to change the values RED GREEN and BLUE via console simply by typing them and a number. Note: the cvars have to be defined in CVAR.BB with a default value. Or, you could re-write the CVAR() function to create a new cvar every time one that doesn't exist is called. :)

Ok, next - not all the console commands are there yet, or not yet perfected. HELP isn't there, for instance. :)

here are some examples:
"CVARLIST" lists all cvars.
"CVARLIST A" lists all cvars starting with A
"CVARLIST LI" lists all cvars starting with LI (get the drift ;))
"FOG_RED" lists the current and default values for FOG_RED
"FOG_RED 2" sets the value of FOG_RED (for instance) to 2
"FOG_RED DEF" sets the value back to default.
"FOG_RED DEFAULT" as above.

changing things like map_width will result in a crash. ;) Don't touch that yet. :) This is just do show you how it works. Hope this helps. :) Lots of code to wade through there..

+BlackD


wizzlefish(Posted 2004) [#5]
I was thinking about this earlier today.


Conan(Posted 2004) [#6]
Hey, BlackD, i liked you console thing, but it came a bit late... I'd worked it out with some crappy code...
Anyway, i forgot to mention that i don't want the console for that game, just that the problem came up while i was doing the game
I actually want it to make a sort of Dynamic Blitz, like, instead of having to run the program, then exit the program, change the code, run the program... you can just code from inside the program. It also generates a source code which should work (but not yet gotten there) and can also be used to do scripting.

Well, that's basically it.

-Conan

P.S. Thanx to all of you!


Damien Sturdy(Posted 2004) [#7]
what aboot that virtual blitz machine proggy? ive never used it but hey it sounds pretty amazing


Progi1984(Posted 2006) [#8]
@BlackD, you file test.zip is not downloadable. Can you put online again ?


jfk EO-11110(Posted 2006) [#9]
Here's a simple example:

legal$="qwertzuiopasdfghjklyxcvbnm,.-;:_1234567890?+*£$%&/()= "+chr$(34)
user$=""

; game mainloop:
while keydown(1)=0
 ;...
 k=Getkey()
 if k<>0
  if instr(legal$,lower$(chr$(k)))>0
   user$=user$+lower$(chr$(k))
  endif
  if k=13
   if user$="god" then godmode=1
   if user$="fly" then ghostmode=1
   if user$="end" then end
   user=""
  endif
 endif
 ; ...
 renderworld()
 text 0,graphicsheight()-stringheight("X"),user$
 flip
wend



Ked(Posted 2006) [#10]
I have a question on how you did that example...
what does the

If k = 13

mean? I know I should know what this means
but hence the question at the beginning. Thanks


jfk EO-11110(Posted 2006) [#11]
k=Getkey() will store the Ascii Number of the previously pressed key (Or zero if no key was hit)in k. The value 13 is used by the key "Return", the carriage return. So you can "send" a line with return. Of course, this simple example doesn't contain any backspace, del, insert etc. capabilities.

For info on ascii codes search for "ascii list" at google. Ascii is not the same as Scancode (used by KeyHit()). Where Keyhit and Keydown may sometimes return false results due to country specific keyboard layouts, GetKey() will always return the true ascii key.