Questions from the forum |
Top Previous Next |
Q: In one of your early AUMs you wrote a script for an eclipse. Could it be possible to update it for us? A: Check the downloadable "Resources" - the updated eclipse code is inside the archive.
Q: I was wondering how I could read a string from a file, process it and then output it to another file. A: Here's an example which read a text file, replaces all the characters with the ones that follow them, and the outputs the result to another file.
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
Q: Does anyone have a sample script showing the assignment of animation sequences to keystrokes? A: Use this example.
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); } }
Q: How can I get a slider to use absolute values such as 1, 2, 3, 4 instead of 1.1 1.2 ... etc? A: Use the following sample as a base for your 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); } }
Q: Is there a way to disable all the audio playing in an A6 game,if some other application window is in focus? A: Use this example.
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); } }
Q: How can I program two cameras within the game engine merged together, so that you can have one camera rendering through the game as a right eye and the other camera rendering as a left eye? A: Disable the default (camera) view and create two different views with different offset_x and / or offset_y values.
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 }
Q: How can I rotate (pan) an entity in a specified direction with a specified speed? A: Use this snippet.
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); }
Q: Is there an easy way to have something happen when you push the left mouse button and something different when you release it? A: Use the following example.
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;
Q: I'd like to click a button on the main menu and take the user to a sub-menu (here it would be a log-in screen). A: There you go:
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 } }
Q: I have noticed that my high-speed flying arrows tend to pass through the target sometimes. How can I avoid this? A: The problem appears because your arrows fly with a huge speed. If the speed is (let's say) 50 quants per frame, the arrow could fly like this.
As you can see, the arrow penetrates the target because it travels 50 quants in a frame. You can lower the speed of the arrow (although you might not want to do this) or you can "fix" the position of the arrow after impact, moving it backwards at the desired position. Since all these things (the impact and the position correction) will happen during the same frame, the process will be invisible to the users and your arrows will stick properly at all times.
|