PDA

Volledige versie bekijken : Multiple lines in string


FredericCox
%Europe/Berlin %037 %2005, 01:53
Hallo , krijg een .csv file geexporteerd en ik wil dus dat als string in mijn flash.


Nu doet ik dat zo

CommentaryFile = "1001;0;5;tv.cTotalGoals == 1;0;A goal so early in the game! We’re in for a treat!;We sure are and I hope many more will follow.;$1002;0;120;(tv.cTotalMissedChances)-(tv.cTotalGoals) < 2;(tv.cHomeGoals>2)&&(tv.cAwayGoals>2);This is a game for the ages... Both keepers are trying to stop the barrage of attacks which are unleashed at their goals.;And they're not doing a good job! Almost every chance has gone in. Poor guys. They deserve that post-game massage.;$
1003;0;120;tv.cHattrick == 1;0;A Hattrick! Incredible. In modern-day soccer, scoring a Hattrick is qui......enzovoort"

Maar nu krijg ik de fout string not literaly terminated. Dus moet ik alles naar één lijn gaan enter, als ik dat elke kee rmoet gaan doen..nou

Is er een andere manier? Of kan ik op een andere manier het einde van die string aanduiden?

TrueChaoZ
%Europe/Berlin %046 %2005, 02:06
Je zou zoiets kunnen doen:
CommentaryFile = "1001;0;5;tv.cTotalGoals == 1;0;A goal so early in the game! We’re in for a treat!;We sure are and I hope many more will follow.;$1002;0;120;";
CommentaryFile += "(tv.cTotalMissedChances)-(tv.cTotalGoals) < 2;(tv.cHomeGoals>2)&&(tv.cAwayGoals>2);This is a game for the ages... Both keepers are trying to stop the barrage of attacks which are unleashed at their goals.;And they're not doing a good job! Almost every chance has gone in. Poor guys. They deserve that post-game massage.;";
CommentaryFile += "$1003;0;120;tv.cHattrick == 1;0;A Hattrick! Incredible. In modern-day soccer, scoring a Hattrick is qui......enzovoort";

FredericCox
%Europe/Berlin %055 %2005, 02:19
Je zou zoiets kunnen doen:
CommentaryFile = "1001;0;5;tv.cTotalGoals == 1;0;A goal so early in the game! We’re in for a treat!;We sure are and I hope many more will follow.;$1002;0;120;";
CommentaryFile += "(tv.cTotalMissedChances)-(tv.cTotalGoals) < 2;(tv.cHomeGoals>2)&&(tv.cAwayGoals>2);This is a game for the ages... Both keepers are trying to stop the barrage of attacks which are unleashed at their goals.;And they're not doing a good job! Almost every chance has gone in. Poor guys. They deserve that post-game massage.;";
CommentaryFile += "$1003;0;120;tv.cHattrick == 1;0;A Hattrick! Incredible. In modern-day soccer, scoring a Hattrick is qui......enzovoort";


Probleem is dat alles tussen de " een csv file is... dus ik zou zoiets moeten kunnen doen zoals bij het commentaar

ipv //Hallo
//Dit
//Is
//test


kan je daar

/* Hallo
Dit
Is
Test
*/

doen

FredericCox
%Europe/Berlin %068 %2005, 02:39
Nog iets, in die string staan dus voorwaarden. bvb TotalGoals==0 bijvoorbeeld

ik splits die string en iets verder doe ik dan bijvoorbeeld

if(CommentArray[p][4]){
doe iets
}

Wordt die voorwaarde ook werkelijk gecontroleerd dan?

Want het werkt niet en daar zit denk ik de fout, de var TotalGoals bestaat er nochtans

if(CommentArray[s][3]){
trace("true " + " | " + CommentArray[s][3])
}
if(CommentArray[s][3] == true){
trace("truetrue " + " | " + CommentArray[s][3])
}

Hij traced alles true+die voorwaarde maar nooit truetrue+voorwaarde

TrueChaoZ
%Europe/Berlin %454 %2005, 11:54
Probleem is dat alles tussen de " een csv file is... dus ik zou zoiets moeten kunnen doen zoals bij het commentaar...Ja ik snap wat je wilt maar ik geloof niet dat dat kan :(

Nog iets, in die string staan dus voorwaarden. bvb TotalGoals==0 bijvoorbeeld

ik splits die string en iets verder doe ik dan bijvoorbeeld

if(CommentArray[p][4]){
doe iets
}

Hiermee kijk je of iets true is en niet of het 0 of 1 is, ik geloof dat je dit af kan vangen met '===' ipv '==', daarnaast als je de string naar een array split dan krijg je in de array allemaal kleine strings, dit betekent dus dat je nu een Boolean wilt vergelijken met een String, dat gaat niet. Je zal dus bijvoorbeeld dit moeten doen:
if(CommentArray[p][4] == "1"){
//doe iets
}

FredericCox
%Europe/Berlin %569 %2005, 14:40
Ja ik snap wat je wilt maar ik geloof niet dat dat kan :(


Hiermee kijk je of iets true is en niet of het 0 of 1 is, ik geloof dat je dit af kan vangen met '===' ipv '==', daarnaast als je de string naar een array split dan krijg je in de array allemaal kleine strings, dit betekent dus dat je nu een Boolean wilt vergelijken met een String, dat gaat niet. Je zal dus bijvoorbeeld dit moeten doen:
if(CommentArray[p][4] == "1"){
//doe iets
}

Maar dat gaat dus wel, via die stringvoorwaarde kijken?


En als ik nu voor dat eerste probleem ComentaryFile = (Extern inladen) doe?

Dauntless
%Europe/Berlin %605 %2005, 15:31
Zo?
var string = "tv.cTotalGoals == 1";
var string2 = string.split(" == ");
var root:MovieClip = this;

//object aanmaken en een var
var tv:Object = new Object();
tv.cTotalGoals = 1;

trace(compare(string2[0], string2[1]));
function compare(path:String, v:String):Boolean {
var string = path.split(".");
var realPath = root;
for (var i = 0; i<string.length; i++) {
realPath = realPath[string[i]];
}
if(String(realPath) == v) return true;
else return false;
}
//en het is dynamisch / flexibel:
var myObject:Object = new Object();
myObject.eenObject = new Object();
myObject.eenObject.naam = "Dauntless";

var string = "myObject.eenObject.naam == Jeroen";
var string2 = string.split(" == ");
trace(compare(string2[0], string2[1]));

Zonee: Weer wat tijd verspilt :p.

FredericCox
%Europe/Berlin %611 %2005, 15:40
Zonee: Weer wat tijd verspilt :p.

Mss kan je het gebruiken, ik leg het ff uit.

De csv bevat tekjens een ID;StartMinuut;EindMinuut;Voorwaarde1;Voorwaarde2; CommentatorZin;CoCommentatorzin


Bedoeling is dus dat adhv voorwaardes een commentaarzin wordt gekozen.



//HIER SPLITS IK DE COMMENTAAR IN APARTE ZINNEN IN EEN ARRAY
AllLinesSep = CommentaryFile.split("$")
CommentArray = new Array();
for(a=0;a<=CommentLines;a++){
LineSep = AllLinesSep[a].split(";")
CommentArray[a] = new Array();
for(b=0;b<=6;b++){
CommentArray[a][b] = LineSep[b];
}
}





//Idnummer;Beginminuut;Eindminuut;Voorwaarde 1;Voorwaarde 2;Commentatorzin;Co-Commentatorzin
/*Categorieën

1) Goals
2) Cards
3) Missed chances
4) Attendance
5) Goal Difference
6) TotalEvents
7) Weather
8) Injuries

9) Fillers
*/
/*SelectArray = new Array();
for(s=0;s<=CommentArray.length;s++){
if(CommentArray[s][0].toString().substr(0,1)==9 && CommentArray[s][3].toString() == "" ){
SelectArray.push(s)
}
}
k = Math.round(Math.random()*SelectArray.length)
trace(CommentArray[SelectArray[k]][5])
trace(CommentArray[SelectArray[k]][6])
Datum = new Date()
Datum1 = Datum.getUTCHours() + ":" + Datum.getUTCMinutes()
InitComm = "B.F"
InitCoComm = "F.C"
Comm = CommentArray[SelectArray[k]][5]
CoComm = CommentArray[SelectArray[k]][6]*/


SelectArray = new Array();
trace("Commentaar toevoegen:")
trace(tv.category)

for(s=0;s<=CommentArray.length;s++){
if(CommentArray[s][3]=="1" && CommentArray[s][4]=="1" && CommentArray[s][0].toString().substr(0,1)!=tv.category && tv.Minutes >= CommentArray[s][1] && tv.Minutes <= CommentArray[s][2] ){
trace(CommentArray[s][3])
if(CommentArray[s][3]=="1"){
trace("true " + " | " + CommentArray[s][3])
}

SelectArray.push(s)
}
}
if(SelectArray.length==0) {
for(t=0;t<=CommentArray.length;t++){
if (tv.Minutes >= CommentArray[s][1] && (tv.Minutes <= CommentArray[s][2]) && (CommentArray[t][3] && CommentArray[t][4])) {
SelectArray.push(t)
}
}

}

k = Math.round(Math.random()*SelectArray.length)
trace(CommentArray[SelectArray[k]][5])
trace(CommentArray[SelectArray[k]][6])
trace(CommentArray[SelectArray[k]][0])
tv.category = Math.round(Math.random() * 8)
tv.category++

Datum = new Date()
Datum1 = Datum.getUTCHours() + ":" + Datum.getUTCMinutes()
InitComm = "B.F"
InitCoComm = "F.C"
Comm = CommentArray[SelectArray[k]][5]
CoComm = CommentArray[SelectArray[k]][6]


_global.addComment(tv.Slot,Datum1,InitComm,Comm)
_global.addCoComment(tv.Slot,Datum1,InitCoComm,CoC omm)



De code hoeft niet zozeer uitleg maar je ziet wat ik telkens wil doen. Een reeks commentaren selecteren die in aanmerking komen adhv de juiste voorwaardes en dan random één van die kiezen uit de SelectArray.

Probleem is dat ik alle commentaren in de selectarray krijg van een bepaalde categorie.
Dus het vergelijken van die minuten en voorwaardes klopt niet echt omdat dat eerst in een string staat.