Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-13-2013, 06:01 PM
JohnnyChimpo JohnnyChimpo is offline
Registered User
JohnnyChimpo's Avatar
Join Date: Jun 2004
Posts: 105
JohnnyChimpo is on a distinguished road
For loop problem

Why does this not put the file string into temp.filename array, the output of this is 0.
PHP Code:

const lngNumber 8;

function 
onActionServerside() {
  for (
temp.=0;i<lngNumber;i++){
    
temp.filename[i] = "levels/translations/server_de.po";
  }

This isn't all the script obviously but when i take the for loop out everything works correctly i'm stumped. Thanks in advance.
Reply With Quote
  #2  
Old 05-13-2013, 07:18 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
tryo to make it

PHP Code:
const lngNumber 8;

function 
onActionServerside() {
  
temp.filename NULL//dont know why, just prefer to set it to NULL before using it
  
for (temp.=0;i<lngNumber;i++){
    
temp.filename.add("levels/translations/server_de.po");
  }

__________________
MEEP!
Reply With Quote
  #3  
Old 05-13-2013, 08:44 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
What are you doing with the variable? You haven't even defined it as an array, so you definitely can't access it like that.
__________________
Reply With Quote
  #4  
Old 05-13-2013, 09:06 PM
Cubical Cubical is offline
Banned
Join Date: Feb 2007
Posts: 1,348
Cubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant future
Quote:
Originally Posted by JohnnyChimpo View Post
Why does this not put the file string into temp.filename array, the output of this is 0.
PHP Code:

const lngNumber 8;

function 
onActionServerside() {
  for (
temp.=0;i<lngNumber;i++){
    
temp.filename[i] = "levels/translations/server_de.po";
  }

This isn't all the script obviously but when i take the for loop out everything works correctly i'm stumped. Thanks in advance.
Why not just store the languages like this
PHP Code:
function onChangeLanguage(lang){
temp.translationfiles = {
{
"English""en"},
{
"Dutch""de"},
{
"Troll""tr"}
};
for(
temp.translationfile temp.translationfiles){
  if(
temp.translationfile[0]  == lang){
// then for your path do something like and whatever else you want to do
loadtranslation("levels/translations/server_" temp.translationfile[1] @ ".po");

I typed this on my phone so by the time i finished i don't know if it went where it needed to go to answer your original question and im sure the formatting is off.
Reply With Quote
  #5  
Old 05-14-2013, 03:38 PM
JohnnyChimpo JohnnyChimpo is offline
Registered User
JohnnyChimpo's Avatar
Join Date: Jun 2004
Posts: 105
JohnnyChimpo is on a distinguished road
Quote:
Originally Posted by callimuc View Post
tryo to make it

PHP Code:
const lngNumber 8;

function 
onActionServerside() {
  
temp.filename NULL//dont know why, just prefer to set it to NULL before using it
  
for (temp.=0;i<lngNumber;i++){
    
temp.filename.add("levels/translations/server_de.po");
  }

That worked thank you very much callimuc, i just have one thing to say however. In the whole grand scheme of things isn't quite inefficient to go and add another function call there? This language should accept the form i had written the first time. That and i could be wrong, but it would be a better means of doing it, based on the two.
Reply With Quote
  #6  
Old 05-14-2013, 06:20 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by JohnnyChimpo View Post
That worked thank you very much callimuc, i just have one thing to say however. In the whole grand scheme of things isn't quite inefficient to go and add another function call there? This language should accept the form i had written the first time. That and i could be wrong, but it would be a better means of doing it, based on the two.
only working with player/npcs attributes. but only because they are only defined.

like cbk said, you didt define it as a array yet. if you really want to use your version you can try this

PHP Code:
const lngNumber 8;

function 
onActionServerside() {
  
temp.filename NULL//like i said before, i prefer to do this
  
for (temp.j=0;temp.j<lngNumbers;temp.j++) {
    
temp.filename.add(""); //this way you are at least creating an array, it will be blank
  
}

  for (
temp.=0;temp.i<lngNumber;temp.i++){
    
temp.filename[i] = "levels/translations/server_de.po";
  }

you have to create the array by using the version i did (using .add("something");) or by creating it like temp.array = {"hi", "", NULL, player.head, 5, ": D"};
__________________
MEEP!
Reply With Quote
  #7  
Old 05-15-2013, 12:18 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by JohnnyChimpo View Post
That worked thank you very much callimuc, i just have one thing to say however. In the whole grand scheme of things isn't quite inefficient to go and add another function call there? This language should accept the form i had written the first time. That and i could be wrong, but it would be a better means of doing it, based on the two.
The first way you wrote it didn't define the array.

You could do...

PHP Code:
// create an array with 8 elements and fill them all with the same thing
const LANGUAGE_COUNT 8;

function 
onActionServerside() {
  
temp.filenameArray = new[LANGUAGE_COUNT]; // this is better than callimuc's version
  
  
for (temp.0temp.LANGUAGE_COUNTtemp.++) {
    
temp.filenameArray[temp.i] = "levels/translations/server_de.po";
  }

but it's a bit silly. Is it faster than using array.add()? Uh, probably, but you'll never notice and there's no reason to over-optimize the code at the expense of readability. I almost never see arrays defined like this (I actually had to look up the syntax to make sure I was right).

PHP Code:
// create an array with 8 elements and fill them all with the same thing
function onActionServerside() {
  
temp.filenameArray = {};
  
  for (
temp.0temp.8temp.++) {
    
temp.filenameArray.add("levels/translations/server_de.po");
  }

I'm not really sure what you're trying to do.

edit: saw this in your other thread, this is better than all of the above:

PHP Code:
function onCreated() {
  
this.languages = {"de","es","fr","it","ne","no","po","sw"}; 
  
this.fileArray = {};
  
  for (
temp.lang this.languages) {
    
this.fileArray.add("levels/translations/server_" temp.lang ".po");
  }

__________________
Reply With Quote
  #8  
Old 05-15-2013, 11:31 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by cbk1994 View Post
The first way you wrote it didn't define the array.

You could do...

[PHP]temp.filenameArray = new[LANGUAGE_COUNT];
never really played with this kind of new stuff (mostly because i didnt need it yet) but cool to know
__________________
MEEP!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 10:50 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.