Hello, I have been working on a "cutscene" program for my game, and I am stuck on some things. By helping me, you will be also helping everyone else, because I have uploaded the source to this thread and anytime in the future when someone comes looking for help on something similar, they will have a "tutorial" of some sorts to fall back on :) .
ERRORS:
1. (line 137) Even though I set the drawing alpha, it does not work. I have tried solutions such as putting it in directly, but it still does not work.
2. (lines 164-176) When you press enter, it moves to the next segment, however the first segment is repeated even though the console shows that segment is in fact 2. If you look in the code there is 5 segments, the 5th segment will show when segment is 6. This makes absolutely no sense.
3. (lines 111 and 116) How do I set z's for put? I want a thumbnail to appear and im pretty sure it does, but you cant see it. Because of this, I am unable to place the 128x128 portrait above the top left of the text box.
4. (i dont know which line) Do you know where the memory leak might occur? I see in task manager the process goes up in ram after every second. I thought it was because of put and write, thats why I made it so it checked to see if they were empty before it put them, but I could be wrong somewhere.
What I would like help with:
1. An easier more optimized way of sorting which line will be shown next. Id like to put in the .txt file "--------------------------------------------------" every fourth line (since the chat box displays three lines) and have the code skip over every line like that, but I have no idea how.
2. From the above, what can I do I would only have to do the
//determining what text will show up in the box
line_screen[1] = line_file[1];
line_screen[2] = line_file[2];
line_screen[3] = line_file[3];
write(font,16,182,0,line_screen[1]);
write(font,16,198,0,line_screen[2]);
write(font,16,214,0,line_screen[3]);
once/twice/whatever is the most optimized in the entire process?
3. Getting rid of that memory leak
Thanks
UPDATE: please update the cutscene process with this:
process cutscene();
private
//backgrounds
int scene; //currently being places
int slide = 1; //currently being shown
int back[2]; //collection
//draw box
int draw_alpha = (255*0.60); //this means it will be at 60%
int draw_colour;
//scene variables
bool character = false; //whether or not the character is on screen
int portrait = 0; //the characters face will appear
int thumbnail; //the graphic end of portrait
int segment = 1; //the current part of the text box
bool segment_change = true;
bool key_continue = false;
//text on the text box
int font;
int dialogue; //the text file is loaded into this
int dialogue_file = "dialogue.txt";
int lines = 20;
string line_screen[3];
string line_file[255];
int c;
begin
//load the backgrounds
back[1] = load_png("back_wo_character.png");
back[2] = load_png("back_w_character.png");
thumbnail = load_png("thumbnail.png");
//create all dialogue said
if(line_file[lines] == "")
dialogue = fopen("dialogue.txt", O_READ);
for (c = 1; c < lines; c++)
line_file[c] = fgets(dialogue);
end
fclose(dialogue);
say("loaded the text");
end
//load font
font = load_fnt("font.fnt");
loop
//place the slide on screen once
if(scene==0)
scene = put(0,back[slide],game_width/2,game_height/2);
end
//place portrait (if possible)
if(character == true)
if(portrait == 0)
portrait = put(0,thumbnail,game_width/2,game_height/2);
end
end
//change slides when the character appears on screen
if(character)
if(slide == 1)
screen_clear();
slide = 2;
scene = 0;
end
end
//create the text box
draw_colour = rgb(0,0,255); //set the colour of the text box
drawing_color(draw_colour);
drawing_alpha(draw_alpha);
drawing_z(0);
draw_box(8,180,(320-8),(240-8));
//determining what text will show up in the box
if(segment_change)
delete_text(all_text);
for(c = 1; c <= 3; c++)
line_screen[c] = line_file[c + 4(segment-1)];
end
segment_change = false;
//put dialogue on screen
write(font,16,182,0,line_screen[1]);
write(font,16,198,0,line_screen[2]);
write(font,16,214,0,line_screen[3]);
end
//moving to next segment
if(key(_enter))
if(!key_continue and !segment_change)
segment++;
segment_change = true;
end
key_continue = true;
else
key_continue = false;
end
frame;end
OnExit
unload_fnt(font);
unload_map(0,back[1]);
unload_map(0,back[2]);
unload_map(0,thumbnail);
end
when I did some work out on paper, I managed to create a formula that could best get things efficiently. The code in there is correct but I keep getting
(http://forum.bennugd.org/index.php?action=dlattach;topic=3551.0;attach=2971)
it just doesnt make any sense, there isn't even a < at line 133.
Ah! It's a typo. Do you mean to multiply something? If so, change it into this: line_screen[c] = line_file[c + (4 * segment) -1];
.
You can put quite complex expressions between the brackets, however the result must always result in an integer number that fits withing the array's range. The compiler actually complained about a ( instead of a <. The console's font makes it easy to mistake between them.
About memory leaks with put, I'm not so sure, as far as I know put doesn't create a new map in memory. Anyway if the array's range is out of bounds, the compiler will complain.
i changed it to
line_screen[c] = line_file[c + (4 * (segment-1))];
you think you can look at the other errors? thanks
Okay I got alot of good stuff working. I forget, how do I convert a string from a text file into a number the variable can understand? Thanks
okay i got something good so far, two errors and then ill be good for now :)
1. this code:
//create all dialogue said
if(line_file[lines] == "")
say("dialogue file opened");
dialogue = fopen("dialogue.txt", O_READ);
for (c = 1; c < 40; c++)
line_file[c] = fgets(dialogue);
say("line#"+c+" "+line_file[c]);
if(line_file[c] == "-end-")
fclose(dialogue);
end
end
segments = atoi(line_file[1]); say("segments: "+segments); //this converts the string to a number
say("dialogue file closed");
end
problem: not really a problem but i would like for c < # to not be the total number of lines in the .txt file but a number like 255 and when it reads "-end-" itll stop there. I tried doing it but it crashed.
2. somewhere between lines 126-135 and 137-174. Nemissa's thumbnail appears at the correct segment, however when you get to the segment with "You nod your head at her", you will see in the .txt file right above that, the segment calls for no thumbnail. Yet, the thumbnail is still there. But for some reason the thumbnail goes away once it goes back to slide 1. I tried changing the name of -slide2- and -slide2--girl- to different things, but it still made no difference.
help me with this, thanks
Quote
i would like for c < # to not be the total number of lines in the .txt file but a number like 255 and when it reads "-end-" itll stop there.
This is possible, there is a predefined compiler macro called "EOF". This is something from C. It stands for "End Of File". It's been a couple of years since I have last used it. The danger is that if your array isn't big enough for the text you have a problem. What you could do is check for EOF and a number like 255 (your array size) to be safe. You could also scan each line for the containing of the string "-end-" with strcasecmp, and when that returns TRUE, break the loop.
using break; helped, thanks! now what can I do to solve the thumbnail issue?
What if you make a different case out of it?
case "-slide1-":
if(slide != 1) map_clear(0,backimage,0); backimage = 0; say("changed slides"); end
character = false;
portrait = false;
slide = 1;
end
case "-slide2-":
if(slide != 2) map_clear(0,backimage,0); backimage = 0; say("changed slides"); end
character = true; //true
portrait = false;
slide = 2;
end
case "-slide2--Girl-": //will also have the portrait of the person talking
if(slide != 2) map_clear(0,backimage,0); backimage = 0; say("changed slides"); end
character = true;
portrait = true;
slide = 2;
end
You've got "slide 2" twice. Maybe you better change "-slide2--Girl-" into slide = 3;. I think there is something double here, probably causing the issue.
B.t.w. I like the gothic girl. But shouldn't she have black hair? I used to dye my hair pitch black when I was younger. :) I was a little bit gothic.
I stated that I tried that already and it did not do anything different. And the girl is just Nemissa from Soul Hackers, lol.
my engine so far appears to be good. however, I never learned how to use the find() command and at this point, im at the part where there aren't really any examples and there isn't much help on the wiki. if you can help me get the kinks out of this, this may be good enough to go in the bennupack examples, lol. if you look in this version, you will see i have multiple slides that are titled "-slide3--answer#-", the reason being is you might not get a reply from an answer in just one slide (cause what if other people have to talk, or it completely changes the route?). if you look in lines 318-324, you will see i made a string called answer and the result puts a string number into answer (is there an easier way to do this? i know atoi converts a string to int). now look at lines 235-247, you will see i kinda changed moving to the next slide; unfortunately, i know absolutely nothing in this area and couldn't find the documentation to help me with it. the best way to understand what i need help with is this flow chart i made.
(http://forum.bennugd.org/index.php?action=dlattach;topic=3551.0;attach=2978)
you will see that in lines 235-238, as long as there is no result, everything is linear. lines 239-246 need major reworking somehow, this is where i am confused. i need it to move to the next segment that still has the correlating answer in its slide name, and if it can no longer find any from that point to the bottom, then it will move on to the next slide that does not have a question-answer in its slide name. you will see i have -slide#--answer#- right now, what I will do later on is change it to -slide#--question#--answer#- when the story gets more advanced, and i assume if i have help just searching for the answer, i may be able to work something so it also only searches for answers pertaining to that question.
i hope someone helps soon, that would be great. thanks
//moving to next segment
if(key(_enter))
if(!key_okay and !segment_change)
if((segment < segments) and result == 0)
segment++;
segment_change = true;
else
say("trying to find a string with "+"-answer"+answer+"-");
for(c = 1; c < 255; c++)
if(find(line_file[4*(segment)+c],"-answer"+answer+"-",0))
//TODO: find formula that goes to specific segment correlating to answer
break;
else
if(!find(line_file[4*(segment)+c],"-answer-",0))
//TODO: find formula that goes to specific segment with no answer
end
end
end
segment++;
segment_change = true;
result = 0;
end
end
key_okay = true;
else
key_okay = false;
end
i have segment++; simple as a placeholder, I kept putting say variables with the line if it found it, and it does not return the correct line, it returns the line of the next segment starter. does the command give up after it sees just one symbol and not the whole specific string? i am really confused, and i checked every bennupack example and the wiki, and there is very little help on this. i would really like to get things working soon.