Jump to content


Photo

3d Array


  • Please log in to reply
28 replies to this topic

#1 szepi1991

szepi1991

    GMC Member

  • New Member
  • 177 posts

Posted 09 April 2007 - 10:12 PM

3D array - very important update!

Note: The values can be only numbers!!
I know that there is another 3D array extension but this one uses a different method and that one is not working yet.

There is a help file included. (I recommend looking at it at least)
The functions:
ar_create(width, height, zheight, init value)
ar_set_value(id,x,y,z,value)
ar_get_value(id, x, y, z) 
ar_get_string(id)
ar_create_fromstring(string)
ar_replace_fromstring(id, string)

I'm open to any ideas (however this doesn't mean that I'll do them <_< ).

Version 1.2:
- bug fixed!
- new function

Version 1.1:
- function name changed from ar_add_value to ar_set_value
- now it works fine when you save it to a file


Download

Edited by szepi1991, 29 April 2007 - 07:51 AM.

  • 0

#2 xygthop3

xygthop3

    You may know me from such forums as "Shaders"

  • GMC Member
  • 3367 posts
  • Version:GM:Studio

Posted 09 April 2007 - 10:19 PM

Sure, I'll take a look because I looked at the other one <_<
  • 0

#3 szepi1991

szepi1991

    GMC Member

  • New Member
  • 177 posts

Posted 10 April 2007 - 02:04 AM

ok
  • 0

#4 xygthop3

xygthop3

    You may know me from such forums as "Shaders"

  • GMC Member
  • 3367 posts
  • Version:GM:Studio

Posted 10 April 2007 - 04:22 AM

Seems ok, might need some more flexibility tho. Eg: set values (rather than just adding) , multiply, randomize etc,etc. Good start but could use some more functions.
  • 0

#5 szepi1991

szepi1991

    GMC Member

  • New Member
  • 177 posts

Posted 10 April 2007 - 12:31 PM

actually the "add value" sets the value..that's because of my english :D Ok, I've done this extension for one of my team's project and we don't need more functions but we will see if I will add some more. (Later)
  • 0

#6 Marchal_Mig12

Marchal_Mig12

    The Rhouan

  • GMC Member
  • 1182 posts
  • Version:GM:Studio

Posted 14 April 2007 - 10:10 PM

Seems ok, might need some more flexibility tho. Eg: set values (rather than just adding) , multiply, randomize etc,etc. Good start but could use some more functions.

<{POST_SNAPBACK}>

well so far, it may be slower, you can get the value and do whatever with it and re-add it.
  • 0

#7 szepi1991

szepi1991

    GMC Member

  • New Member
  • 177 posts

Posted 15 April 2007 - 07:22 AM

yeah :angry:
  • 0

#8 IsmAvatar

IsmAvatar

    Good Samaritan

  • GMC Member
  • 2411 posts
  • Version:GM8

Posted 19 April 2007 - 12:43 AM

insteady of ar_add_value, you should call it ar_set_value (similar to the Java naming convention)
  • 0
Posted Image LateralGM is an IDE for editing GM files on Linux, Mac, and Windows.
We also house the GM File Format Documentation and other projects of that nature.
IsmAvatar.com | Examples | Scripts | Particles | DLLs | Credit Me
Email | Registered

#9 szepi1991

szepi1991

    GMC Member

  • New Member
  • 177 posts

Posted 19 April 2007 - 06:09 AM

Allright, I change its name and add a few more functions during the next weekend.
  • 0

#10 softhunterdevil

softhunterdevil

    LazyBoy

  • GMC Member
  • 276 posts

Posted 19 April 2007 - 02:44 PM

Make a 4D array!!!

3D for position and another D for time variable.

Edited by softhunterdevil, 19 April 2007 - 02:46 PM.

  • 0
<a href="http://www.redbubble...eactdevelopers" target="_blank"><img src="http://www.redbubble...rb_profile.gif" border="0" class="linked-sig-image" /></a><a href="http://www.redbubble...eactdevelopers" target="_blank"><img src="http://www.redbubble...ers_banner.jpg" border="0" class="linked-sig-image" /></a>

#11 szepi1991

szepi1991

    GMC Member

  • New Member
  • 177 posts

Posted 19 April 2007 - 09:31 PM

I'm making a game for a competion nowadays, and the game is due the end of April and I could work on it only 2 days and it's a 3D game, so I have lots to do.

After April maybe..but wgy would that be good anyway? What could you use it fot?
  • 0

#12 Spectek

Spectek

    GMC Member

  • New Member
  • 542 posts

Posted 19 April 2007 - 09:41 PM

What would you use a time variable for? Just make an object that adds one to a variable every step.
  • 0

#13 szepi1991

szepi1991

    GMC Member

  • New Member
  • 177 posts

Posted 20 April 2007 - 03:19 AM

yeah <_< no real use..although You could use it for something else such as i don't know what XD
  • 0

#14 DavidA325

DavidA325

    GMC Member

  • New Member
  • 157 posts

Posted 22 April 2007 - 09:43 PM

Yeah when I try to use ar_create_fromstring after getting the string to use from a file, I get this error (It might be helpful to know that the initial value is set to zero):

ERROR in
action number 1
of Key Press Event for F4 Key
for object obj_player:

In script load:
In extension function ar_create_fromstring:
Error in code at line 17:
  b=string_count(" /", str)/c;

at position 28: Division by 0.

I really need this function - can you help me out here?
-David
  • 0
Back from the dead? Maybe.
DCM Software.net

#15 szepi1991

szepi1991

    GMC Member

  • New Member
  • 177 posts

Posted 22 April 2007 - 10:23 PM

I'll check it and edit if I find the bug and upload the fixed version (I will also change the name of ar_add_value(id,x,y,z,value))

EDIT: could you copy the array string here please?
I'd need it, cause it works for me, and "c" is the number of layers, so it shouldn't/can't be 0. Maybe I'll be able to find the problem if I can look at your string.

Edited by szepi1991, 22 April 2007 - 10:31 PM.

  • 0

#16 DavidA325

DavidA325

    GMC Member

  • New Member
  • 157 posts

Posted 22 April 2007 - 10:38 PM

Yeah, I got it working. I was saving it to a value in an INI file to save the trouble of adding another file. But I tried just saving it to a regular text file and it worked then, but now it throws a bunch of funky errors at me saying that theres something wrong with the real() function. Which is odd because I didn't use it in the script and even stranger is if I click abort, it works perfectly... instead of closing the game. And it only does it on the first time. Oh well in the final product I'll turn errors off and tell it to abort on all of them.

Thanks for looking into my problem,
-David

Edited by DavidA325, 22 April 2007 - 10:39 PM.

  • 0
Back from the dead? Maybe.
DCM Software.net

#17 szepi1991

szepi1991

    GMC Member

  • New Member
  • 177 posts

Posted 22 April 2007 - 10:54 PM

Yeah, I got it working. I was saving it to a value in an INI file to save the trouble of adding another file. But I tried just saving it to a regular text file and it worked then, but now it throws a bunch of funky errors at me saying that theres something wrong with the real() function. Which is odd because I didn't use it in the script and even stranger is if I click abort, it works perfectly... instead of closing the game. And it only does it on the first time. Oh well in the final product I'll turn errors off and tell it to abort on all of them.

Thanks for looking into my problem,
-David

<{POST_SNAPBACK}>

As you said this, I checked it and it's not working..I'll reupload the fixed version.

It's not working only when you save it to a file, so I'm going to redo the creating string and reading from it now, so it will work when you save it to a file.

EDIT: Ok, fixed, now it should work fine when you save it to a file (it works for me). Uploading

hmm...there's another error. I'll pm you when it's uploaded

Edited by szepi1991, 22 April 2007 - 11:16 PM.

  • 0

#18 DavidA325

DavidA325

    GMC Member

  • New Member
  • 157 posts

Posted 22 April 2007 - 11:18 PM

As you said this, I checked it and it's not working..I'll reupload the fixed version.

It's not working only when you save it to a file, so I'm going to redo the creating string and reading from it now, so it will work when you save it to a file.

EDIT: Ok, fixed, now it should work fine when you save it to a file (it works for me). Uploading

hmm...there's another error. I'll pm you when it's uploaded

<{POST_SNAPBACK}>


Okay, sounds great. Will this get rid of the real() errors?

-David
  • 0
Back from the dead? Maybe.
DCM Software.net

#19 szepi1991

szepi1991

    GMC Member

  • New Member
  • 177 posts

Posted 22 April 2007 - 11:38 PM

sorry for bumping:

New, WORKING version uploaded

edit: no bump ^_^

Edited by szepi1991, 23 April 2007 - 12:07 AM.

  • 0

#20 szepi1991

szepi1991

    GMC Member

  • New Member
  • 177 posts

Posted 28 April 2007 - 07:22 PM

there's another error...last time I got something similar for error, than changed the code and changed it back and it worked. I think I won't check for errors, since that part is not working

edit: never mind, the person who reported the bug forgot to create the array

EDIT: Actually I have found a bug!
and you won't be able to save strings. I will fix that next weekend.

Edited by szepi1991, 28 April 2007 - 09:11 PM.

  • 0

#21 IamCalle

IamCalle

    GMC Member

  • GMC Member
  • 444 posts

Posted 04 May 2007 - 02:58 AM

Right on..! xD
  • 0

#22 Scooternew

Scooternew

    GMC Member

  • New Member
  • 1325 posts

Posted 06 May 2007 - 03:35 AM

Why not just use a grid data structure?
  • 0

#23 IamCalle

IamCalle

    GMC Member

  • GMC Member
  • 444 posts

Posted 26 June 2007 - 11:57 AM

Hmm, I have no answer to that. :)

- Anyway; @szepi1991: You have to add functions for getting each independent value! =O (Like "ar_get_value_x", and so on.)
  • 0

#24 goldnoah

goldnoah

    GMC Member

  • New Member
  • 39 posts

Posted 30 July 2007 - 08:51 PM

why not a code as:

ini_open("array.ini")
ini_write_string(argument0,"a"+string(argument1)+" "+string(argument2)+" "+string(argument3)+" "+string(argument4)+" "+string(argument5)+" "+string(argument6)+" "+string(argument7)+" "+string(argument8) ,argument9)
ini_close()

[SIZE=1]sorry for my bad english
  • 0

#25 IamCalle

IamCalle

    GMC Member

  • GMC Member
  • 444 posts

Posted 30 July 2007 - 10:52 PM

Why not code what as
ini_open("array.ini")

ini_write_string(argument0,"a"+string(argument1)+" "+string(argument2)+" "+string(argument3)+" "+string(argument4)+" "+string(argument5)+" "+string(argument6)+" "+string(argument7)+" "+string(argument8) ,argument9)

ini_close()
??
  • 0

#26 goldnoah

goldnoah

    GMC Member

  • New Member
  • 39 posts

Posted 02 August 2007 - 09:04 AM

Why not code what as

ini_open("array.ini")
ini_write_string(argument0,"a"+string(argument1)+" "+string(argument2)+" "+string(argument3)+" "+string(argument4)+" "+string(argument5)+" "+string(argument6)+" "+string(argument7)+" "+string(argument8) ,argument9)
ini_close()
??

<{POST_SNAPBACK}>


write 9d array why not?
  • 0

#27 takis76

takis76

    GMC Member

  • GMC Member
  • 57 posts

Posted 22 June 2009 - 08:51 PM

<span style='font-size:15pt;line-height:100%'>3D array - very important update!</span>

Note: The values can be only numbers!!
I know that there is another 3D array extension but this one uses a different method and that one is not working yet.

There is a help file included. (I recommend looking at it at least)
The functions:

ar_create(width, height, zheight, init value)
ar_set_value(id,x,y,z,value)
ar_get_value(id, x, y, z) 
ar_get_string(id)
ar_create_fromstring(string)
ar_replace_fromstring(id, string)

I'm open to any ideas (however this doesn't mean that I'll do them :) ).

Version 1.2:
- bug fixed!
- new function

Version 1.1:
- function name changed from ar_add_value to ar_set_value
- now it works fine when you save it to a file


Download



Your extension is greate , but if you are able to create 4D array version of your extension?
I use it in my game and I will put a credit for you.
But 4D is crucial for my game.

I use 1st array to put all my levels
I use 2nd and 3rd array to make dimensions of each level in squares 32x32 square
I will use 4th array to make the sides of each of my square (North - South - West - East).

my_array=ar_create(Number_of_Levels,width, height,sides,my_value);
ar_set_value(my_array,Number_of_Levels,width,height,sides,m
y_value);

Your 3D extension was fast , I thing the 4D could be fast as 3D.

Thank you very much.
  • 0

#28 Stephen_789

Stephen_789

    GMC Member

  • GMC Member
  • 68 posts
  • Version:GM:Studio

Posted 04 August 2014 - 12:26 AM

whenever I try to make a second array of the same dimensions it comes up with an error and states:

 

trying to index variable that is not an array
 at gml_Script_ar_create (line 2) - if (variable_global_exists("numb_asdfgf"))
 
any ideas on why?

  • 0

-Stephen_789

              Geek Conglomerate

              Now on YouTube!


#29 takis76

takis76

    GMC Member

  • GMC Member
  • 57 posts

Posted 05 October 2015 - 12:40 AM

Since the Game Maker became studio so those extensions are very old. Today I was played with this and I think I was fixed it.

 

In Game Maker old versions 8.1 and before all argument variables was as argument0 , argument1 , argument2 etc...

The new format of arguments are like argument[0] , argument[1] , argument[2] etc..

 

If you load the old extension in the game maker studio the extension will load some gml code in a file with name 3d_arry_scripts.gml

In this file you will see all source codes. This if (variable_global_exists("numb_asdfgf")) is an absolete code , which means new versions of game maker studio does not use them anymore.

 

 

If you Rem out the absolete code it will not work. But you can change this

//Rem out this
/*
if (variable_global_exists("numb_asdfgf"))
    
    global.numb_asdfgf+=1;
else
    global.numb_asdfgf=0;
*/

//Replace it with this:
global.numb_asdfgf=0;

if (global.numb_asdfgf==0)
    global.numb_asdfgf+=1;
else
    global.numb_asdfgf=0;



global.width_asdfgf[global.numb_asdfgf]=argument[0]; //Replace all argument0 with argument[0] do the same with 1 ,2 and 3
global.height_asdfgf[global.numb_asdfgf]=argument[1];
global.zheight_asdfgf[global.numb_asdfgf]=argument[2];

var a, b, c;

for (a=0; a<=global.width_asdfgf[global.numb_asdfgf]-1; a+=1)
{
    for (b=0; b<=global.height_asdfgf[global.numb_asdfgf]-1; b+=1)
    {
        for (c=0; c<=global.zheight_asdfgf[global.numb_asdfgf]-1; c+=1)
        {
            global.array_asdfgf[global.numb_asdfgf, global.width_asdfgf[global.numb_asdfgf]*global.height_asdfgf[global.numb_asdfgf]*c+global.width_asdfgf[global.numb_asdfgf]*b+a]=argument[3];
        }
    }
}

return global.numb_asdfgf;

Replace all argument0 with argument[0] just add square bracket to argument[0] and argument[1] and argument[2] and argument[3]

Do the same in all source codes.

 

The variable_global_exists() function just sees if there is a global variable so set a default global variable with name numb_asdfgf and set a default value 0

This means the global variable will be created.

 

The example:

//Create a global variable with name level 10x10x10 or any name you want
global.level=ar_create(10, 10, 10, "00");

//set any value at x,y,z values , you can put and strings too
ar_set_value(global.level,1,1,1,"01"); //x=1 y=1 z=1
ar_set_value(global.level,1,2,1,"02"); //x=1 y=2 z=1

//store the result of your variable to other variable with name global.my_val
global.my_val=ar_get_value(global.level,1,1,1);

//Look what you have stored
draw_text_colour(20,100,string(global.my_val),c_white,c_white,c_white,c_white,1);

//store the result of your variable to other variable with name global.my_val
global.my_val=ar_get_value(global.level,1,2,1);

//Look what you have stored
draw_text_colour(20,120,string(global.my_val),c_white,c_white,c_white,c_white,1);

global.my_val=ar_get_value(global.level,5,5,1);
draw_text_colour(20,140,string(global.my_val),c_white,c_white,c_white,c_white,1);

This works and fixes this 3D Arrays in Game Maker Studio.

All other x,y,z values have "00"

 

You will have this output:

 

"01"

"02"

"00"


Edited by takis76, 05 October 2015 - 12:45 AM.

  • 0