Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 12-15-2014, 05:18 PM
khortez khortez is offline
PrototypeX
khortez's Avatar
Join Date: Dec 2008
Posts: 91
khortez will become famous soon enough
confusion on array and random()

someone was asking for help on this (probably have an idea of what you're thinking or going to say about that but anyway...)


they wanted to make it so whenever they pressed a key, a random image would be selected every time. I suggested putting the images in an array and using random(); referencing the array list. but what i attempted actually didn't work. and i'm not sure why. any clue on what happened? here is my attempt

i won't use their actual image for this example since they're all strings anyway.

PHP Code:
function onCreated(){
  
temp.images = { "test1",  "test2"}; 
  
temp.random int(random(temp.images[0], temp.images[1]));
  echo(
temp.random);

i also tried something a friend of mine did. which was

PHP Code:
function onCreated(){
  
temp.images = { "test1""test2" };
  
temp.random int(random(0temp.images.size() ));
  echo(
temp.random);

i also put the data in echo directly. but no matter how i did it they all came out as: -1, 0, -1

or: 1, 0.

are those correct outputs? was i wrong in expecting it to output the images name or whats happening?
Reply With Quote
 


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 06:21 PM.


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