Questions from the forum |
Top Previous Next |
Q: File_var_write writes the variables separating them with a space, but I would like them to be separated by a comma. How can I do that? A: There you go.
var number1 = 10; var number2 = 20; var number3 = 30;
STRING* temp_str = "#10"; // allow number that have up to 10 digits
function write_vars() { var filehandle = file_open_write("myvars.txt"); str_for_num(temp_str, number1); // convert the first number to a string file_str_write(filehandle, temp_str); // write the first string to the file file_str_write(filehandle, ","); // add a comma separator str_for_num(temp_str, number2); // convert the 2nd number to a string file_str_write(filehandle, temp_str); file_str_write(filehandle, ","); str_for_num(temp_str, number3); // convert the 3rd number to a string file_str_write(filehandle, temp_str); file_close (filehandle); // time to close the file }
function write_startup() { on_v = write_vars; }
Q: I have a text with 10 strings. How do I display them one by one, with a delay of 5 seconds between them? A: Use this snippet as a base for your code.
FONT* arial_font = "Arial#20";
STRING* display_str = "#100";
TEXT* names_txt = { strings = 10; // stores up to 10 strings string = "My name is Jimmy"; string = "or Joe, can't remember it exactly"; string = "see, my dad always told me"; string = "Son, no matter what you do"; string = "if you get caught"; string = "doing something nasty"; string = "they'll ask"; string = "what your name is"; string = "so it's best"; string = "to forget it."; }
TEXT* display_txt = { pos_x = 30; pos_y = 50; font(arial_font); string = display_str; flags = SHOW; }
function text_startup() { var index; wait (-5); // wait for 5 seconds for (index = 0; index < 10; index++) { str_cpy(display_str, (names_txt.pstring)[index]); wait (-3); // wait 3 seconds before displaying the next string } }
Q: The script I am working with uses a panel with several buttons that are loading different levels. Nevertheless, the panel will not disappear from the screen after the level loads behind it. Is there any script example that removes the panel when I click a button to run the level? A: Sure thing!
BMAP* pointer_tga = "pointer.tga";
BMAP* level11_tga = "level11.tga"; BMAP* level12_tga = "level12.tga"; BMAP* level21_tga = "level21.tga"; BMAP* level22_tga = "level22.tga"; BMAP* level31_tga = "level31.tga"; BMAP* level32_tga = "level32.tga";
function load_level1(); function load_level2(); function load_level3();
PANEL* main_pan = { layer = 10; bmap = "main.jpg"; pos_x = 0; pos_y = 0; button (250, 10, level12_tga, level11_tga, level12_tga, load_level1, NULL, NULL); button (250, 50, level22_tga, level21_tga, level22_tga, load_level2, NULL, NULL); button (250, 90, level32_tga, level31_tga, level32_tga, load_level3, NULL, NULL); flags = SHOW; }
function mouse_startup() { mouse_mode = 2; mouse_map = pointer_tga; while (1) { vec_set(mouse_pos, mouse_cursor); wait(1); } }
function load_level1() { reset(main_pan, SHOW); // hide the panel before loading the level level_load ("level1.wmb"); }
function load_level2() { reset(main_pan, SHOW); // hide the panel before loading the level level_load ("level2.wmb"); }
function load_level3() { reset(main_pan, SHOW); // hide the panel before loading the level level_load ("level3.wmb"); }
Q: -d name=[value] Through this instruction, a user can change variables in the script. Isn't this dangerous? Is there a way to disable this once the game is published? A: Here's a quick example that does what you want.
function commands_startup() { if (!str_cmp(command_str, "")) // the engine was run using a command line option? { printf("So you wanna hack my game, huh? Well, it won't happen today!"); sys_exit(NULL); } }
Q: How do I make sure that my entities are carried from one level to the other properly, always appearing in the right position? A: Place the entities in each new level, in the position where you want them to appear - they aren't carried from one level to another automatically. If you want to preserve their skill values, save them to variables before loading the new level, and then copy them back from the variables to the skills (after the new level has loaded).
Q: Is there a simple solution that would allow me to adjust the color of my rocks (models) in real time, displaying their RGB values of the screen? A: Sure! Use the code below, move the mouse over the desired rock, and then use the 1...6 keys to set the proper RGB values.
BMAP* pointer_tga = "pointer.tga";
function mouse_startup() { mouse_mode = 2; mouse_map = pointer_tga; while (1) { vec_set(mouse_pos, mouse_cursor); wait(1); } }
function debug_startup() { while (1) { if(mouse_ent) // the mouse touches an entity? { set(mouse_ent, LIGHT); if (key_1) {mouse_ent.red += 5 * time_step;} if (key_2) {mouse_ent.red -= 5 * time_step;} if (key_3) {mouse_ent.green += 5 * time_step;} if (key_4) {mouse_ent.green -= 5 * time_step;} if (key_5) {mouse_ent.blue += 5 * time_step;} if (key_6) {mouse_ent.blue -= 5 * time_step;} } wait (1); } }
PANEL* time_pan = { layer = 15; digits(10, 10, "Red: %.f", *, 1, mouse_ent.red); digits(10, 30, "Green: %.f", *, 1, mouse_ent.green); digits(10, 50, "Blue: %.f", *, 1, mouse_ent.blue); flags = SHOW; }
Q: I'd like to generate nine balls that have random movement directions and random speeds, reacting to collisions with each other and with the other entities in the level. A: There you go:
function collision_event() { vec_to_angle(my.pan,bounce); // change direction even if the ball has collided with one of the level blocks my.pan += 10 - random(20); // add a bit more randomness }
function bouncing_ball() { var ball_speed = 2 + random(10); var ball_orientation = random(360); // make the entity sensitive for block and entity collision my.emask |= (ENABLE_BLOCK | ENABLE_ENTITY); my.event = collision_event; while(1) { c_move(my, vector(ball_speed * time_step, 0, 0),nullvector, NULL); wait(1); } }
function balls_startup() { var i; random_seed(0); // starts with random initial values for (i = 0; i < 10; i++) { ent_create("ball.mdl", vector(200 - random(400), 200 - random(400), -150), bouncing_ball); // all the balls are created at z = -150 } }
Q: How do you count the number of entities that have a certain skill set to a certain value? Counting them in Wed is almost impossible in my situation. A: Here’s a fully functional example:
var counter = 0;
function detect_entities() { you = ent_next(NULL); // retrieve the first entity while (you) { if (you.skill1 == 123) counter += 1; you = ent_next(you); // move on to the next entity } }
function detect_startup() { on_d = detect_entities; // press "D" to count all the entities that have their skill1 set to 123 }
PANEL* time_pan = { layer = 15; digits(10, 10, "Special entities: %.f", *, 1, counter); flags = SHOW; }
Q: What tool are you using to compile the AUMs, George? A: I was asked this question many times, so there you go: the tool I'm using is named "Help & Manual". It's a WYSIWYG editor with lots of features, but it's quite expensive (the basic edition starts at $400). More information can be found here:
Q: How can I use the entity's string1 to set its name in Wed, and then display it when the mouse pointer is moved over it? A: Here’s a fully functional example:
BMAP* pointer_tga = "pointer.tga";
STRING* name_str = "#30"; // the name can have up to 30 characters
function mouse_startup() { mouse_mode = 2; mouse_map = pointer_tga; while (1) { vec_set(mouse_pos, mouse_cursor); wait(1); } }
TEXT* name_txt = { pos_x = 50; pos_y = 20; string (name_str); }
function strings_startup() { while (1) { if (mouse_ent) { str_cpy(name_str, mouse_ent.string1); // read the name from the entity's string1 set(name_txt, SHOW); } else { reset(name_txt, SHOW); } wait (1); } }
|