Schrift
[thread]806[/thread]

Problem mit einem cgi script - Interactive Story: Anfänger braucht Hilfe

Leser: 2


<< >> 8 Einträge, 1 Seite
Gast Gast
 2006-08-31 02:16
#8619 #8619
Hallo!

Ich würde mich wirklich freuen wenn mir jemand bei meinem Problem helfen kann - ich selber habe leider nicht allzuviel Ahnung. :blush:

Es geht um das Interactive Story script: www.valeriemates.com/interactive_story.html

Und zwar erzeugt der code unter anderem eine "outline"-Seite, die die sich verästelnden Wege der Interaktiven Geschichte als verlinkte Kapitel anzeigt. Nur ab Kapitel 50 werden diese nicht mehr im "outline" angezeigt (man kann sie trotzdem noch erreichen wenn man ab Kapitel 50 die weiterführenden links zum nächsten Kapitel anklickt), und ab Kapitel 63 kann man keine neuen Kapitel mehr veröffentlichen. Das script sagt dann "Invalid chapter name".


Hier ist jetzt der Teil des codes wo sich das Problem befinden muss - ich nehme mal laienhaft an, dass es etwas damit zu tun hat, wie sich das script die Kapitelnummern berechnet. Im script selbst steht ja auch "Do some fancy formatting on the chapter numbers, so that they don't print out in scientific notation", aber ich werde daraus einfach nicht schlau. :(

Es wäre echt super falls mir jemand helfen kann!

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
   # The next page of the story exists (and hasn't snuck in
# while we were writing a different new page).
# Read it in and display it.

if (!(open(STORY, "<$nextfile"))) {
print "Could not open file $nextfile to read it!<br>\n";
} else {
# Read data from story file:
$author_name = <STORY>;
$author_email = <STORY>;
$chapter_title = <STORY>;
$next_text_1 = <STORY>;
$next_text_2 = <STORY>;

chomp($author_name);
chomp($author_email);
chomp($chapter_title);
chomp($next_text_1);
chomp($next_text_2);

$chapter = 1 + $in{'chapter'};

print "<b><font size=+2>Chapter $chapter: $chapter_title</font></b><p>\n";

if (($author_name ne "") || ($author_email ne "")) {
$author = "$author_name
<a href=\"mailto:$author_email\">$author_email</a>";
} else {
$author= "an anonymous author";
}
print "<center><i>this page added by $author</i></center><p>\n";

while (<STORY>) {
print $_;
}

$next_num_1 = 2 * $in{'next'};
$next_num_2 = $next_num_1 + 1;

# Do some fancy formatting on the chapter numbers, so that they
# don't print out in scientific notation. This only becomes
# important when users enter chapters more than 50 levels deep. !!!
$next_num_1 = format_chapter_number($next_num_1);
$next_num_2 = format_chapter_number($next_num_2);

print <<EOF;
<p>
<hr>
<p>
What do you do now?

<p>
<table>
<tr>
<td valign=bottom>
<a href="story.pl?next=$next_num_1&chapter=$chapter"><img
src="$image_url/pink_story_arrow.gif" width="15" height="16" alt=""
border=0></a>
</td>
<td valign=top>
<a href="story.pl?next=$next_num_1&chapter=$chapter">$next_text_1</a>
</td>
</tr>

<tr>
<td valign=bottom>
<a href="story.pl?next=$next_num_2&chapter=$chapter"><img
src="$image_url/green_story_arrow.gif" width="15" height="16" alt=""
border=0></a>
</td>
<td valign=top>
<a href="story.pl?next=$next_num_2&chapter=$chapter">$next_text_2</a>
</td>
</tr>
</table>


<p>

EOF
}


} elsif ($in{'submit'} eq "") {
# The next page of the story doesn't exist.
# Ask the user to enter it.

print <<EOF;
<h1>Your Turn</h1>

You have reached the end of the story action.

<p>Now it's your turn to enter what happens next in the story.

<blockquote>

<form action="story.pl" method="post">
<b>Your name: </b> (optional) <br>
<input type="text" name="author_name" size=50 maxlength=50> <br>

<b>Your email address: </b> (optional) <br>
<input type="text" name="author_email" size=50 maxlength=50> <br>

<br><b>The next part of the story:</b> <br>
<textarea rows=10 cols=60 name="story_text" wrap="physical"></textarea> <br>

<br>
<b>The two things the reader can do next: </b><br>
Option One: <input type="text" name="next_text_1" size=60 maxlength=100> <br>
Option Two: <input type="text" name="next_text_2" size=60 maxlength=100> <br>

<br>
<b>A title for your chapter:</b> <br>
<input type="text" name="chapter_title" size=60 maxlength=80> <br>

<input type="hidden" name="next" value="$in{'next'}">
<input type="hidden" name="chapter" value="$in{'chapter'}">

<br>
<input type="submit" name="submit" value="Enter it!">
</input>

</form>

</blockquote>

EOF

} else {
# The user has entered a next page.
# See if it's okay. If it is, save it.

# Convert newlines to <br> html in the story:
$in{story_text} =~ s/\n/<br>\n/gio;

# Don't let people create any old file:
$prev_page_num = format_chapter_number(int($in{'next'} / 2));
if (($in{'next'} ne "1") && (! -e "$story_dir/$prev_page_num.txt")) {
print "<b>Invalid chapter name!</b><br>";

# Check for any missing text:
} elsif ($in{story_text} eq "") {
print "<b>Please write the description of what happens now.</b><br>";
print "Press your browser's 'Back' button to add it.";
} elsif (($in{next_text_1} eq "") || ($in{next_text_2} eq "")) {
print "<b>Please enter two options for what the user can do next.</b><br>";
print "Press your browser's 'Back' button to add this.";
} elsif ($in{chapter_title} eq "") {
print "<b>Please enter a title for your chapter.</b><br>";
print "Press your browser's 'Back' button to add it.";
} else {

# Make sure file is still available.
if (-e $nextfile) {
print <<EOF;
<p><b>Ooops! Someone else entered this section of the story
while you were typing. I can't enter your section</b>.

<p><center>
<a href="story.pl?next=$in{'next'}&chapter=$in{'chapter'}&reload=$bignum">See it</a>
</center>

<p><b><blockquote><blockquote><blockquote><blockquote>After you select the
"See it" link, you may need to press the 'Reload' button on your browser
to see what the other person
entered.</blockquote></blockquote></blockquote></blockquote></b><br>
EOF
} else {

# Save it!
if (!open(STORY, ">$nextfile")) {
print "Oh oh. I couldn't open the file '$nextfile' to save your
section. (Error: $!) So I didn't save it.\n";
} else {
print STORY "$in{author_name}\n";
print STORY "$in{author_email}\n";
print STORY "$in{chapter_title}\n";
print STORY "$in{next_text_1}\n";
print STORY "$in{next_text_2}\n";
print STORY "$in{story_text}\n";
close(STORY);

print <<EOF;
Your addition to the story has been saved.
Thorium
 2006-08-31 15:08
#8620 #8620
User since
2003-08-04
232 Artikel
BenutzerIn
[Homepage] [default_avatar]
Die sub format_chapter_number wäre hilfreich - so kann man nichts darüber sagen...
Per|li|nist der; -en, -en <zu ↑...ist>: a) Anhänger, Vertreter der radikalen Perlinisten die Perl als die einzig wahre Sprache ansehen; b) Mitglied einer perlinistischen Community.
Melanie
 2006-08-31 19:09
#8621 #8621
User since
2006-08-31
3 Artikel
BenutzerIn
[default_avatar]
OK, ich hoffe das hier ist das richtige Stück:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#
# The "outline" option recursively calls this function to print a chapter
# and see if it has any subchapters.
#
sub outline_tree {
if (-e "$story_dir/$_[0].txt") {

$auth = "";
$title = "";

if (open(CHAPTER, "$story_dir/$_[0].txt")) {
$auth = <CHAPTER>;
$junk = <CHAPTER>;
$title = <CHAPTER>;
close(CHAPTER);

chomp($auth);
chomp($title);

if ($auth ne "") {
$auth = "by $auth";
}
}

#print "&nbsp;&nbsp;&nbsp;";
print "&nbsp;|&nbsp;" x ($_[1] - 1);
print "&nbsp;+-";
$x = format_chapter_number($_[1] - 1);
print "Chapter $_[1]: <a href=\"story.pl?next=$_[0]&chapter=$x\">$title</a> $auth\n";

outline_tree(2 * $_[0], $_[1] + 1);
outline_tree((2 * $_[0]) + 1, $_[1] + 1);

$chapter_count++
}
}


#
# Do some fancy formatting on the chapter numbers, so that they
# don't print out in scientific notation. This only becomes
# necessary when users enter chapters more than 50 levels deep!!!
#
sub format_chapter_number {
my $my_chapter_number = $_[0]; # Parameter is chapter number.
return(sprintf("%.0f", $my_chapter_number));
}


Falls nicht bitte sagen, dann poste ich das komplette script; ich wollte hier nur nicht alles zuspammen weil es doch ganz schön lang ist. :blush:
renee
 2006-08-31 19:44
#8622 #8622
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Schau das Skript doch mal durch und such nach irgendwelchen Bedinungen, die etwas mit 50 bzw. 63 abfragen...
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/
Melanie
 2006-08-31 23:38
#8623 #8623
User since
2006-08-31
3 Artikel
BenutzerIn
[default_avatar]
Nein, da sehe ich nichts... ???

Hier ist der komplette code zum ansehen, vielleicht hilft das ja.
vayu
 2006-09-01 10:08
#8624 #8624
User since
2005-01-13
782 Artikel
BenutzerIn
[default_avatar]
hmmm .. könnte es vielleicht an der config datei liegen? ^^

Quote
# Read our configuration. Any customization for a particular site is
# stored in the config file. No changes to this file (story.pl) should
# be required.
require("storyconfig");


eine der ersten zeilen von oben?
Melanie
 2006-09-01 21:58
#8625 #8625
User since
2006-08-31
3 Artikel
BenutzerIn
[default_avatar]
Die storyconfig enthält nichts relevantes, das sehe sogar ich. ;)

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/local/bin/perl

# This file contains configurable settings for story.cgi program.
# Change these values as needed for your particular site.
# Any customization for a particular site can be made here in the
# storyconfig file. No changes to the story.pl program should
# be required.

#
# Interactive Story program written by Valerie Mates, [EMAIL=valerie@cyberspace.org]valerie@cyberspace.org[/EMAIL]
# 1/15/98.
#
# This program is freeware, but, if you use it, you are required
# to leave my URL in the page footer and send me an email message
# (valerie@cyberspace.org) to let me know that you are using it.
#
# If you translate the program to another language, I would appreciate a
# copy to add to the collection of translated versions. This is not
# required, but it is appreciated.
#
# The program is not permitted for use on pornographic sites.
#

# This is the name of the directory where the story data is stored.
# You'll need to make sure it exists -- that the web server can write to it.
# By default, this program uses a directory called "story" under the
# cgi-bin directory.
$story_dir = "story";

# URL of image directory, or "." if they are in the same directory
# as this script:
$image_url = "../images";

# Your own web page URL
# Example: $host_url = "http://www.yourhost.com/~yourlogin";
$host_url = "/";

# Email address to send mail to when each new page is posted. Or leave
# blank to not send e-mail. IMPORTANT: Put a \ before any @ characters!
# Example: $announce_to = "you\@somewhere.com";
$announce_to = "";

# Location of your sendmail program, if you want the program to send
# you mail about each new response. (Unix only.)
$sendmail = "/usr/lib/sendmail";

# URL of header image, and the image's width and height and alt text.
$header_image = "$image_url/an_interactive_story.gif";
$image_width = 498;
$image_height = 131;
$image_alt = "An Interactive Story";
Dubu
 2006-09-03 02:45
#8626 #8626
User since
2003-08-04
2145 Artikel
ModeratorIn + EditorIn

user image
Meiner Ansicht nach müsste sich die "50er-Grenze" durch einen kleinen Patch beseitigen lassen (ungetestet!):
Code: (dl )
1
2
3
4
5
6
7
8
9
Ersetze Zeile 484:
   if (-e "$story_dir/$_[0].txt") {
durch die folgenden:
   my $fname = format_chapter_number($_[0]);
   if (-e "$story_dir/$fname.txt") {
Ersetze Zeile 489 (dann 490):
      if (open(CHAPTER, "$story_dir/$_[0].txt")) {
durch die folgende:
      if (open(CHAPTER, "$story_dir/$fname.txt")) {


Wenn ich das richtig sehe, ist dann aber wahrscheinlich trotzdem bei 53 Leveln Schluss, weil ab n=53 die Integer-Auflösung nicht mehr ausreicht und somit 2**n das Gleiche wie (2**n) +1 ergibt, trotz des netten Tricks mit sprintf().

Wenn man das Schema in der bisherigen Art weiterführen möchte, könnte man z.B. komplett auf Math::BigInt umsteigen, was aber einige Änderungen am Programm nötig machte.
<< >> 8 Einträge, 1 Seite



View all threads created 2006-08-31 02:16.