Fragen aus dem Forum

Top  Previous  Next

F: In einem der füheren AUMs haben Sie ein Skript für eine Sonnenfinsternis. Könnten Sie diese aktualisieren?

A: Prüfen Sie den "Resources" Ordner - der Code ist im Archiv.

 

 

F: Ich habe mich gefragt, ob es möglich ist, einen String aus einer Datei zu lesen, diesen zu verarbeiten und in eine andere Datei zu schreiben.

A: Hier ist ein Beispiel, das aus einer Textdatei liest, alle Zeichen durch die jeweils nachfolgenden ersetzt und das Ergebnis in eine andere Datei schreibt.

 

var_nsave filehandle;

var number_of_characters;

var string_index;

 

STRING initial_str;

STRING replaced_str;

STRING backup_str;

STRING temp_str;

 

function process_characters()

{

       filehandle = file_open_read("initial.txt"); // put your text inside the initial.txt file

       file_str_read(filehandle, initial_str);

       file_close (filehandle);

       number_of_characters = str_len(initial_str);

       string_index = 0;

       str_cpy(replaced_str, "");

       while (string_index < number_of_characters) // process the string char by char

       {

               str_cpy(backup_str, initial_str);

               str_clip(backup_str, string_index);

               str_trunc(backup_str, number_of_characters - string_index - 1);

               temp = str_to_asc(backup_str); // read a character and convert it to its ascii value

               str_for_asc(temp_str, temp + 1); // increment the numerical value and convert the number back to string

               str_cat (replaced_str, temp_str);

               string_index += 1;

       }

       filehandle = file_open_write ("final.txt"); // the processed text will be output to the final.txt file

       file_str_write (filehandle, replaced_str);

       file_close (filehandle);

}

 

on_p = process_characters; // press "P" to process the characters

 

 

F: Haben Sie ein Beispielskript, das zeigt, wie man gewissen Tasten Animationssequenzen zuweist?

A: Hier ist ein Beipiel.

 

action animate_me // attach this action to your model

{

       while (1)

       {

               if (key_p) // press "P" to play the punch animation

               {

                       my.skill90 = 0;

                       while (my.skill90 < 98) // play with 98

                       {

                               ent_animate(me, "punch", my.skill90, NULL);

                               my.skill90 += 5 * time; // 5 = animation speed

                               wait (1);

                       }

                       while (key_p) {wait (1);}

               }

               if (key_k) // press "K" to play the kick animation

               {

                       my.skill90 = 0;

                       while (my.skill90 < 98) // play with 98

                       {

                               ent_animate(me, "kick", my.skill90, NULL);

                               my.skill90 += 5 * time; // 5 = animation speed

                               wait (1);

                       }

                       while (key_k) {wait (1);}

               }

               if (key_b) // press "B" to play the block animation

               {

                       my.skill90 = 0;

                       while (my.skill90 < 98) // play with 98

                       {

                               ent_animate(me, "block", my.skill90, NULL);

                               my.skill90 += 5 * time; // 5 = animation speed

                               wait (1);

                       }

                       while (key_b) {wait (1);}

               }

               wait (1);

       }

}

 

 

F: Wie kann ich einen Slider dazu bringen, nur ganze Werte wie 1, 2, 3, 4 etc. anzunehmen und keine krummen Zwischenwerte?

A: Hier ist ein Beispiel als Grundlage für Ihren Code.

 

var resolution = 5; // can be set to exactly 0, 1, 2, 3, 4 or 5

 

PANEL my_pan =

{

       bmap = "main.pcx";

       pos_x = 250;    

       pos_y = 200;   

       vslider (16, 71, 90, "slider.pcx", 0, 5, resolution);

       digits (15, 50, 3, _a4font, 1, resolution);

       flags = OVERLAY | VISIBLE;

}

 

function slider_startup()

{

       while (1)

       {

               while (mouse_left) {wait (1);} // wait until the player releases the left mouse button

               if (resolution <= 0.5)

               {

                       resolution = 0; // snap to the first position

               }

               if ((resolution > 0.5) && (resolution < 1.5))

               {

                       resolution = 1; // snap to the second position

               }

               if ((resolution >= 1.5) && (resolution < 2.5))

               {

                       resolution = 2; // snap to the third position

               }

               if ((resolution >= 2.5) && (resolution < 3.5))

               {

                       resolution = 3; // snap to the fourth position

               }

               if ((resolution >= 3.5) && (resolution < 4.5))

               {

                       resolution = 4; // snap to the fifth position

               }

               if (resolution >= 4.5)

               {

                       resolution = 5; // snap to the sixth position

               }

               wait (1);

       }

}

 

 

F: Ist es möglich, alle Sounds abzustellen, wenn eine andere Anwendung in Windows aktiviert ist?

A: Verwenden Sie dieses Beispiel.

 

function control_sounds_startup()

{

       var temp_master = 100; // set the initial master volume here

       var act_once = 0;

       while (1)

       {

               if (window_focus == 0) // the engine is in the background?

               {

                       if (act_once == 0)

                       {

                               act_once = 1;

                               temp_master = master_vol;

                               master_vol = 0;

                       }

               }

               else

               {

                       master_vol = temp_master;

                       act_once = 0;

               }

               wait (1);

       }

}

 

 

F: Wie kann ich zwei Kameras programmieren, so dass die eine das Spiel rendert, wie es mit dem rechten und das andere wie es mit dem linken Auge wahrgenommen wird?

A: Schalten Sie die voreingestellte camera View ab und erstellen Sie zwei verschiedene Views mit Werten für offset_x und / oder offset_y.

 

view camera1_view =

{                

       layer = 0;

       pos_x = 0;

       pos_y = 0;

       size_x = 400;

       size_y = 600;

       arc = 65;

       aspect = 1;

       ambient = 10;

       offset_x = -0.45;

       flags = VISIBLE;

}

 

view camera2_view =

{                

       layer = 0;

       pos_x = 400;

       pos_y = 0;

       size_x = 400;

       size_y = 600;

       arc = 65;

       aspect = 1;

       ambient = 10;

       offset_x = 0.45;

       flags = VISIBLE;

}

 

function set_views_startup()

{

       camera.visible = off; // the new views are set up for a 800x600 pixels resolution

}

 

aum63_faq2

 

 

F: Wie kann ich eine Entity mit bestimmter Geschwindigkeit in eine bestimmte Richtung drehen?

A: Hier ist ein Beispiel.

 

function rotate_me(target_pan, rotation_speed)

{

       while (ang(my.pan - target_pan) < -2)

       {

               my.pan -= rotation_speed * time_step;

               wait (1);

       }

       while (ang(my.pan - target_pan) > 2)

       {

               my.pan += rotation_speed * time_step;

               wait (1);

       }

}

 

action my_entity // just an example

{

       rotate_me(60, 5);

       sleep (5);

       rotate_me(130, 3);

       sleep (4);

       rotate_me(-40, 10);

}

 

 

F: Gibt es eine einfache Methode, etwas geschehen zu lassen, wenn die linke Maustaste gedrückt wird und etwas anderes, wenn sie losgelassen wird?

A: Verwenden Sie das folgende Beispiel.

 

function test_mouse()

{

       beep; // do something here, the mouse button was pressed

       while(mouse_left) {wait (1);} // wait until the button was released

       beep; beep; // do something else here, the mouse button was released

}

 

on_mouse_left = test_mouse;

 

 

F: Ich würde gern nach Klick auf einen Knopf im Hauptmenü den Spieler in ein Untermenü bringen (in diesem Fall ein Login-Bildschirm).

A: Kein Problem:

 

STRING serial_str; // the password can have up to 20 characters

 

function check_password();

 

PANEL main_pan =

{

       bmap = "main.pcx";

       pos_x = 250;    

       pos_y = 200;   

       button (250, 134, "loginclicked.pcx", "loginnormal.pcx", "loginover.pcx", check_password, NULL, NULL);

       flags = OVERLAY | VISIBLE;

}

 

PANEL login_pan =

{

       bmap = "login.tga";

       flags = overlay, refresh;

       layer = 15;

       pos_x = 280;

       pos_y = 250;

}

 

TEXT login_txt =

{

       layer = 25;

       pos_x = 300;

       pos_y = 275;

       string = serial_str;

}

 

function check_password()

{

       main_pan.visible = off;

       login_pan.visible = on;

       login_txt.visible = on;

       inkey (serial_str);

       if (str_cmpi(serial_str, "acknex") == 0) // password = acknex

       {

               sys_exit(NULL); // wrong password? Then shut down the game

       }

       else // good password? Then move on with the game

       {

               login_pan.visible = off;

               login_txt.visible = off;

               beep;

               // put the code that starts your game here

       }

}

 

 

F: Ich habe bemerkt, dass meine Hochgeschwindigkeitspfeile manchmal durch das Ziel hindurch fliegen. Wie kann ich das vermeiden?

A: Das Problem besteht darin, dass die Pfeile sich mit sehr großer Geschwindigkeit bewegen. Wenn die Geschwindigkeit (zum Beispiel) 50 Quants pro Frame ist, sieht die Flugbahn eventuell so aus.

 

aum63_faq1

Wie Sie sehen, schießt der Pfeil über das Ziel hinaus, weil er sich so schnell fortbewegt. Sie könnten den Pfeil langsamer fliegen lassen (was vermutlich nicht gewollt ist) oder die Position des Pfeils nach dem Aufprall "reparieren", indem Sie ihn nach hinten bewegen. Da all diese Dinge (der Aufprall und die Korrektur) im selben Frame geschehen, wird der User nichts bemerken und die Pfeile sind präzise plaziert.