0 registered members (),
984
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Two simple questions
#424595
06/19/13 09:45
06/19/13 09:45
|
Joined: Jan 2013
Posts: 106 Only in your imagination!
The_KING
OP
Member
|
OP
Member
Joined: Jan 2013
Posts: 106
Only in your imagination!
|
I want to ask two questions: 1) If I use "#include" instruction to add a script to the main one, how can I make the variables, pointers...etc. defined in the main including script able to be used in the included script (if that is possible)? 2)Here is my code of a script included in the main script (I intend to make cut scenes and at first I want to write the word "Location: China" with an effect such that every 0.5 second, a letter is written without using animated sprites):
VIEW* movie_camera1 =
{
layer = 5;
pos_x = 0;
pos_y = 0;
size_x = screen_size.x;
size_y = screen_size.y;
arc = 60;
x = 5800;
y = 0;
z = 2036;
tilt = -20;
pan = 181;
genius = NULL;
flags = UNTOUCHABLE;
}
/////////////////////////////////////////
TEXT* location_info =
{
pos_x = (screen_size.x/2)-50;
pos_y = screen_size.y-10;
layer = 0;
font = "arial#16b";
blue = 255;
green = 20;
red = 25;
string("L");
flags = 0;
}
///////////////////////////////////////
function play_movie1 (a)
{
var CamPanStore;
var time_passed = 0;
if (a == 0)
{
set(camera,0);
set(movie_camera1,SHOW);
}
CamPanStore = movie_camera1.pan;
while(time_passed < 20)
{
movie_camera1.pan -= 0.5*time_step;
time_passed += time_step/16;
if (time_passed == 0.5) str_cat(location_info.pstring[0],"o");
if (time_passed == 1) str_cat(location_info.pstring[0],"c");
if (time_passed == 1.5) str_cat(location_info.pstring[0],"a");
if (time_passed == 2) str_cat(location_info.pstring[0],"t");
if (time_passed == 2.5) str_cat(location_info.pstring[0],"i");
if (time_passed == 3) str_cat(location_info.pstring[0],"o");
if (time_passed == 3.5) str_cat(location_info.pstring[0],"n");
if (time_passed == 4) str_cat(location_info.pstring[0],":");
if (time_passed == 4.5) str_cat(location_info.pstring[0]," ");
if (time_passed == 5) str_cat(location_info.pstring[0],"C");
if (time_passed == 5.5) str_cat(location_info.pstring[0],"h");
if (time_passed == 6) str_cat(location_info.pstring[0],"i");
if (time_passed == 6.5) str_cat(location_info.pstring[0],"n");
if (time_passed == 7) str_cat(location_info.pstring[0],"a");
wait(1);
}
}
The problem is: when I run the main (not the included above) script, the engine says, "subscript requires array or pointer type <if (time_passed >= 0.5) str_cat(location_info.pstring[0],"o");>" Thank you for reading
Last edited by The_KING; 06/19/13 09:56.
|
|
|
Re: Two simple questions
[Re: The_KING]
#424596
06/19/13 10:19
06/19/13 10:19
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
Hello, 1. Declare the global variables before including the code file.
#include <acknex.h>
PANEL *myGblPanel;
#include "myheader.h"
2. You have to acces to the string as follows:
(location_info.pstring)[0]
The pstring member of a TEXT is a pointer to a string struct array. Look at those new parethesis. If you don't write them, you are trying to acces to the 0th member of pstring, and it is not an array so it becomes to that error. When writing the parethesis, you are trying to access the 0th member of the array pointed by pstring. Salud!
|
|
|
Re: Two simple questions
[Re: txesmi]
#424636
06/19/13 17:00
06/19/13 17:00
|
Malice
Unregistered
|
Malice
Unregistered
|
Also that IF() setup is going to miss because you are using == and chances that your time_var is going to be exactly == is very small. EDIT* and the == compares var as/like int without decimals for comparing decimal parts of vars use < > not == or != ...
var time_passed_old =0 ;
var loop_count = 0;
while(time_passed < 20)
{
movie_camera1.pan -= 0.5*time_step;
time_passed += time_step/16;
if(time_passed - time_passed_old > 0.5)
loop_count += 1;
switch(loop_count)
{
case 1:
time_passed_old = time_passed;
str_cat((location_info.pstring)[0],"o");
break;
case 2:
time_passed_old = time_passed;
str_cat((location_info.pstring)[0],"c");
break;
// you should get the idea I don't have time to finish this snip //
}
wait(1);
}
Last edited by Malice; 06/19/13 17:14.
|
|
|
Re: Two simple questions
[Re: The_KING]
#424639
06/19/13 17:22
06/19/13 17:22
|
Joined: Jan 2013
Posts: 106 Only in your imagination!
The_KING
OP
Member
|
OP
Member
Joined: Jan 2013
Posts: 106
Only in your imagination!
|
@txesmi Thank you. It worked for me. @Malice I changed my code to work perfectly. And I used that way (replaced "str_cat" with "str_cpy"):
while(time_passed < 20)
{
movie_camera1.pan -= 0.5*time_step;
time_passed += time_step/16;
if (time_passed >= 0.1) str_cpy((location_info.pstring)[0],"Lo");
if (time_passed >= 0.2) str_cpy((location_info.pstring)[0],"Loc");
if (time_passed >= 0.3) str_cpy((location_info.pstring)[0],"Loca");
if (time_passed >= 0.4) str_cpy((location_info.pstring)[0],"Locat");
if (time_passed >= 0.5) str_cpy((location_info.pstring)[0],"Locati");
if (time_passed >= 0.6) str_cpy((location_info.pstring)[0],"Locatio");
if (time_passed >= 0.7) str_cpy((location_info.pstring)[0],"Location");
if (time_passed >= 0.8) str_cpy((location_info.pstring)[0],"Location:");
if (time_passed >= 0.9) str_cpy((location_info.pstring)[0],"Location: ");
if (time_passed >= 1) str_cpy((location_info.pstring)[0],"Location: C");
if (time_passed >= 1.1) str_cpy((location_info.pstring)[0],"Location: Ch");
if (time_passed >= 1.2) str_cpy((location_info.pstring)[0],"Location: Chi");
if (time_passed >= 1.3) str_cpy((location_info.pstring)[0],"Location: Chin");
if (time_passed >= 1.4) str_cpy((location_info.pstring)[0],"Location: China");
wait(1);
}
Just another question: I liked the font "Agency FB" in the Windows ,but when I write the following in a text definiton ,the default font is used though: Also tried: PEACE
Last edited by The_KING; 06/19/13 17:29.
|
|
|
Re: Two simple questions
[Re: The_KING]
#424640
06/19/13 17:39
06/19/13 17:39
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
To write, letter by letter, I suggest you use something like this:
FONT* arial_font = "Arial#20b";
TEXT* mytxt =
{
layer = 1;
pos_x = 100;
pos_y = 100;
string ("qwert yuiop asdfg hjkl zxcvb nm,. n qwert yuiop asdfg hjkl zxcvb nm,");
font = arial_font;
}
void letter_by_letter(TEXT* _temp_field,int _string,int _delay)
{
if(!_temp_field){return;}
STRING* temp_string = "meow";
TEXT* temp_text = txt_create(1,1);
layer_sort(temp_text,_temp_field.layer+1);
temp_text.font = _temp_field.font;
temp_text.pos_x = _temp_field.pos_x;
temp_text.pos_y = _temp_field.pos_y;
temp_text.size_y = _temp_field.size_y;
set(temp_text, SHOW);
reset(_temp_field, SHOW);
int i;
for(i = 0;i<str_len((_temp_field.pstring)[_string]);i++)
{
str_cpy(temp_string,(_temp_field.pstring)[_string]);
str_trunc(temp_string,str_len(temp_string)-i);
str_cpy((temp_text.pstring)[0],temp_string);
wait(_delay);
}
set(_temp_field, SHOW);
ptr_remove(temp_text);
}
void main()
{
level_load(0);
wait(5);
fps_max = 100;
letter_by_letter(mytxt,0,5);
wait(-2);
letter_by_letter(mytxt,0,20);
}
It's not made by me, but I hope it helps anyway. Greets
|
|
|
Re: Two simple questions
[Re: 3run]
#424642
06/19/13 18:36
06/19/13 18:36
|
Malice
Unregistered
|
Malice
Unregistered
|
@3Run Greet function but it maybe a little confusing for him could you tell a little more about what is happing in the function. Because learning the ideas behind the code is the real lesson.
@The_KING try moving the font into the work folder and renaming it AGencyFB without spaces or special characters. Think I remember that as a solution . Also be sure to provide fonts with the publish project because I don't have that font and you can't be sure any other user will.
Last edited by Malice; 06/19/13 18:54.
|
|
|
Re: Two simple questions
[Re: The_KING]
#424644
06/19/13 19:12
06/19/13 19:12
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
Malice@ function is very simple, it does: * creates a temp text * hides the actual text that contains the string (_temp_field) * after that, it takes the string from the text (take a look at the example above) * then, it detects the number of characters in the actual string * it starts adding those characters (from the text's string) into the temp text, one by one (letter by letter) * it does that with the given delay time (_delay) * at the end, it hides the temp text and destroys it * it shows the actual text (_temp_field) I hope, this really helps. Greets
|
|
|
Re: Two simple questions
[Re: 3run]
#424647
06/19/13 20:30
06/19/13 20:30
|
Malice
Unregistered
|
Malice
Unregistered
|
I can't do anything about particles now no time... Maybe later tonight my function had a problem this should fix it. But please if you tell me what went wrong it helps track down the bug.
var time_passed_old =0 ;
var loop_count = 0;
var loop_lock =1;
while(time_passed < 20)
{
movie_camera1.pan -= 0.5*time_step;
time_passed += time_step/16;
if(time_passed - time_passed_old > 0.5)
{
loop_count += 1;
loop_lock = 0;
}
if(!loop_lock)
{
switch(loop_count)
{
case 1:
time_passed_old = time_passed;
loop_lock =1;
str_cat((location_info.pstring)[0],"o");
break;
case 2:
time_passed_old = time_passed;
loop_lock = 1;
str_cat((location_info.pstring)[0],"c");
break;
// you should get the idea I don't have time to finish this snip //
}
}
wait(1);
}
you can replace str_cat with the str_cpy of course. @Run thanks for the walk through.
Last edited by Malice; 06/19/13 20:33.
|
|
|
Re: Two simple questions
[Re: ]
#424652
06/19/13 22:23
06/19/13 22:23
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
There is a very usefull couple of functions for these cases: str_getchr and str_setchr
STRING *strPanel = "#1";
STRING *strText = "Location: China ";
PANEL *panLetter =
{
digits ( 20, 20, strPanel, *, 1, 0 );
flags = SHOW;
}
function main ()
{
wait(1);
var nCount = 1;
while ( !key_esc )
{
str_setchr ( strPanel, 1, str_getchr ( strText, nCount ) );
nCount += 1;
if ( nCount > str_len ( strText ) )
nCount = 1;
wait(-0.5);
}
sys_exit ( NULL );
}
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|