Internal Key Scripts
From GameStudio Wiki
Internal script functions assigned to keys
The engine has some simple internal script functions for moving the camera, displaying the debug panel, switching video resolution and so on. The C-Script equivalent of those functions is listed here. It can be used as a template for writing your own key functions. For lite-C the key functions are not internal, but contained in the default.c file in the include folder.
action _quit() { sys_exit(); } // F10
action _save() { game_save(app_name,1,SV_ALL-SV_INFO); beep(); } // F2
action _load() { game_load(app_name,1); } //F3
var _sn;
action _sshot() { // F6
file_for_screen("shot_",_sn);
beep();
_sn+=1;
}
var _mvol_old=50;
var _svol_old=50;
action _tog_sounds() { // F12
if (sound_vol==0) { sound_vol=_svol_old; midi_vol=_mvol_old; return; }
if (midi_vol==0) { _svol_old=sound_vol; sound_vol=0; return; }
_mvol_old=midi_vol; midi_vol=0;
}
VIEW camera = { flags = VISIBLE | AUDIBLE;}
VIEW _map = { flags = LINES | NOCULL; layer = 1; roll = 270; tilt = -90; arc = 10; }
action main() { _move_straight(); }
action _mv() {
_map.VISIBLE = (_map.VISIBLE == OFF);
while (_map.VISIBLE) {
vec_set(_map.x,camera.x);
_map.z += 10000;
wait(1);
}
}
var _camera;
var _cam_dist;
var _force; // ahead force
var _aforce; // angular force
var _speed;
var _aspeed;
var _dist;
entity* player;
action _move_straight() {
if (player == NULL) { _camera=2; }
while (_camera) {
_aforce.tilt = 5*(key_pgup-key_pgdn+mouse_force.y);
if (key_alt==0) {
_aforce.pan = -5*(key_force.x+mouse_force.x+joy_force.x);
_aforce.roll = 0;
} else {
_aforce.pan = 0;
_aforce.roll = 5*(key_force.x+mouse_force.x+joy_force.x);
}
vec_add(camera.pan,vec_accelerate(_dist,_aspeed,_aforce,0.8));
_force.x=7*(key_force.y+joy_force.y+mouse_right);
_force.y=3*(key_comma-key_period);
_force.z=3*(key_home-key_end);
vec_accelerate(_dist,_speed,_force,0.5);
if (player != null && _camera==1) {
me = player;
ent_move(_dist,nullvector);
camera.genius = me;
vec_set(my.pan,camera.pan);
vec_set(camera.x,_cam_dist);
vec_rotate(camera.x,camera.pan);
vec_add(camera.x,my.x);
} else {
camera.genius = null;
vec_add(camera.x,vec_rotate(_dist,camera.pan));
}
wait(1);
}
}
action _tog_mov() { // 0
_camera+=1;
if (_camera > 2) { _camera=0; }
if (_camera > 0) {
beep;
if (key_shift==0) { _move_straight(); }
}"
}"
action _toggle_video() { // F5
temp=video_mode;
while(1) {
if (key_shift==0) {temp+=1;} else {temp-=1;}
if (temp>11) {temp=6;}
if (temp<6) {temp=11;}
if (video_switch(temp,0,0)) {break;}
}
}
action _toggle_screen() { // Alt-Enter
if (key_alt == 0) { return; }
temp = video_screen + 1;
if (temp > 2) { temp = 1; }
video_switch(0,0,temp);
if (result == 0) { beep; }
}
STRING _cstr[128];
TEXT _ctxt = { string(_cstr); layer = 999; }
TEXT _debug_txt = {
pos_x = 2; pos_y = 2; layer = 999;
strings = 2; string(debug_str,watch_str);
flags = VISIBLE;
}
action _console() { // Tab
_ctxt.pos_x=2;_ctxt.pos_y=screen_size.y-10;
_ctxt.visible=1;
inkey(_cstr);
if (result==13){execute(_cstr);}
_ctxt.visible=0;
}
var _dfps;
var _dtps;
var _dtlv;
var _dtcs;
var _dtac;
var _cang[3];
PANEL _dbg_pan = {
pos_x = 4; pos_y = 2; layer = 998;
digits 0,2," <%.0f>",_a4font,1,screen_size.x;
digits 0,12,"fps%5.0f",_a4font,16,_dfps;
digits 0,22,"kps%5.0f",_a4font,0.016,_dtps;
digits 0,32,"x%7.0f",_a4font,1,camera.x;
digits 0,42,"y%7.0f",_a4font,1,camera.y;
digits 0,52,"z%7.0f",_a4font,1,camera.z;
digits 0,62,"pan%5.0f",_a4font,1,_cang.pan;
digits 0,72,"til%5.0f",_a4font,1,_cang.tilt;
digits 0,82,"rol%5.0f",_a4font,1,_cang.roll;
digits 65,2,"ms/frame",_a4font,0,0;
digits 65,12,"geo%5.1f",_a4font,1,_dtlv;
digits 65,22,"ent%5.1f",_a4font,1,time_entities;
digits 65,32,"par%5.1f",_a4font,1,time_effects;
digits 65,42,"mir%5.1f",_a4font,1,time_portals;
digits 65,52,"pan%5.1f",_a4font,1,time_panels;
digits 65,62,"ref%5.1f",_a4font,1,time_update;
digits 65,72,"srv%5.1f",_a4font,1,_dtcs;
digits 65,82,"fnc%5.1f",_a4font,1,_dtac;
digits 65,92,"phy%5.1f",_a4font,1,time_physics;
digits 130,2," numbers",_a4font,0,0;
digits 130,12,"ent%5.0f",_a4font,1,num_entities;
digits 130,22,"vis%5.0f",_a4font,1,num_visents;
digits 130,32,"par%5.0f",_a4font,1,num_particles;
digits 130,42,"med%5.0f",_a4font,1,num_mediastreams;
digits 130,52,"fnc%5.0f",_a4font,1,num_actions;"
digits 200,2,"memory kb",_a4font,0,0;
digits 200,12,"nex%6.0f",_a4font,1,nexus;
digits 200,22,"geo%6.0f",_a4font,1,d3d_texsurfs;
digits 200,32,"sha%6.0f",_a4font,1,d3d_texsmaps;
digits 200,42,"ent%6.0f",_a4font,1,d3d_texskins;
digits 200,52,"bmp%6.0f",_a4font,1,d3d_texbmaps;
digits 200,62,"fre%6.0f",_a4font,1,d3d_texfree;
digits 270,2,"network",_a4font,0,0;
digits 270,12,"lat%4.0f",_a4font,1,dplay_latency;
digits 270,22,"bps%4.0f",_a4font,1,dplay_bps;
digits 270,32,"bpk%4.0f",_a4font,1,dplay_bpspeak;
digits 270,42,"rel%4.0f",_a4font,1,dplay_bpsreliable;
digits 270,52,"unr%4.0f",_a4font,1,dplay_bpsunreliable;
digits 270,62,"drp%4.0f",_a4font,1,dplay_dropped;
}
action _tog_dbg() { // F11
beep();
if(key_shift) {
freeze_mode=(freeze_mode==0);
if(freeze_mode){
mouse_mode[1]=mouse_mode;
mouse_mode=2;
mouse_pointer=2;
}else{
mouse_mode=mouse_mode[1];
}
while(freeze_mode){
mouse_pos.x=pointer.x;
mouse_pos.y=pointer.y;
if(mouse_left) { watched=mouse_ent; }
wait(1);
}
return;
}
if(key_ctrl) {
_mv();
return;
}
if(d3d_lines==1){
_dbg_pan.visible=0;
d3d_lines=0;
}else{
if(_dbg_pan.visible==1){
d3d_lines=1;
}else{
_dbg_pan.visible=1;
while(_dbg_pan.visible==1){
_dfps=0.9*_dfps+0.1/time_frame;
_dtps=0.9*_dtps+0.1*num_vistriangles/time_frame;
_dtlv=time_level+time_sky;
_dtcs=time_client+time_server+time_idle;
_dtac=time_actions+time_pfuncs;
vec_set(_cang,camera.pan);
_cang.pan%=360;
_cang.roll%=360;
while(_cang.tilt<-180){_cang.tilt += 360;}
while(_cang.tilt>180){_cang.tilt -= 360;}
wait(1);
}
}
}
}
The above code is for version 6.31. Do not call internal functions in your own script! First, they may (and will) change with every engine version. Second, they are only available in the development, but not in the release engine. Better copy the code above for your own functions.
