Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Adding Sub Array (https://forums.graalonline.com/forums/showthread.php?t=134267760)

sssssssssss 01-13-2013 01:11 AM

Adding Sub Array
 
Every time I use .add or .addarray to a blank or valued array variable I get a funky, dirty array that has to be sort through like hell in a very annoying way.


for example:

PHP Code:

temp.holder.addarray({temp.checkQuestparams[1]}); 

temp.checkQuest and params[1] are single value vars. The output is


PHP Code:

"""1,"",","Fake Quest 1" 

when I echo temp.holder, and I'm trying to insert holder into another array, but its nasty and almost useless like this.

wtf? I'm lost....

fowlplay4 01-13-2013 01:31 AM

Works fine for me, what are you trying to do?

PHP Code:

function onCreated() {
  
temp.a.add(1);
  echo(
temp.a);
  
temp.a.add(2);
  echo(
temp.a);
  
temp.a.addarray({3,4});
  echo(
temp.a);
  
temp.a.add({5,6});
  echo(
temp.a);
}

/* Output:

1,
1,2
1,2,3,4
1,2,3,4,"5,6"

*/ 


sssssssssss 01-13-2013 01:37 AM

Put a passing id and quest name in a clientr.var.

wnpc:
PHP Code:

function onActionServerside()
{
  switch (
params[0])
  {
    case 
"addQuest":
      
temp.checkQuest req("SELECT rowid FROM Quests WHERE name = '" @params[1]@ "'"true);
      if (
temp.checkQuest != null)
      {
        
temp.holder.addarray({temp.checkQuestparams[1]});
        
        echo(
temp.holder);
        
clientr.activeQuests.add(temp.addArray);
      }
    break; 


The rowid is obvious what it is, 0; 1; 2; ect.
The params sent in the test I'm doing is from.....

same wnpc (clientside):
PHP Code:

// Function to add in quests
public function addQuest(temp.questName)
{
  if (
temp.questName in clientr.activeQuests)
  {
    return 
"active";
  }else
  {
    
triggerServer("gui"this.name"addQuest"temp.questName);
  }


(which obviously the first if statement isn't working b/c the array is jacked)

and that temp.questName is coming from a level npc joined class as....

class:
PHP Code:

//#CLIENTSIDE
function onCreated()
{
  
this.quest "Fake Quest 1";
}
function 
onPlayerTouchsMe()
{
  
findweapon("-System/QuestTracker").addQuest(this.quest);


for now nothing is set on the level npc itself, it's set in the class, just trying to get it to work first...

sssssssssss 01-13-2013 02:08 AM

It's the return from the database iteself actually, not the way its adding the array...

There some kind of protocol for the fields so grabbing database records doesn't show up all jacked up?

had to make temp.checkQuest[0][0] to get the first field....

fowlplay4 01-13-2013 02:51 AM

Use the rows from the SQL result.

PHP Code:

temp.data req("your sql query");
for (
temp.rowtemp.data.rows) {
  
temp.ids.add(temp.row.rowid);
}
echo(
temp.ids); 

Also escape/validate your params in the SQL query. I.e: escapestring2(params[1]) or for numbers int(params[1]) or float(params[1]).

sssssssssss 01-13-2013 03:07 AM

Thanks you.


All times are GMT +2. The time now is 05:37 PM.

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