help 2d array! :S

Monkey Forums/Monkey Beginners/help 2d array! :S

monoloc(Posted 2014) [#1]
as I can make an array of 100x100
and then read some of that grid point.

example of as well in, basic

dim tiles.L (100,100)

tiles (15.22) = 39

if tiles(15.22) = 39
print "found"
endif

look at some examples that they placed in the forum but I did not work any
maybe I'm used to a very simple use

example in forum

http://www.monkey-x.com/Community/posts.php?topic=7817


Global Width:Int=12
Global Height:Int=8
Global myArray:Int[][]

myArray = AllocateArrayInt(Width,Height) <<<<<<<<<< ERROR

+------------------------------------------------------+
c(O._.o)o Compile error
+------------------------------------------------------+
/!\ Syntax error -expecting class member declaration.

+ OK +
+-----------------------------------------------------



myArray[3][5] = 7
myArray[5][3] = 3

For Local x:Int = 0 Until myArray[0].Length
For Local y:Int = 0 Until myArray[1].Length
Print myArray[x][y]
Next
Next


therevills(Posted 2014) [#2]
Wrong thread sorry:-(


dawlane(Posted 2014) [#3]
I take it that you just copied the code the Supertino posted? If so then Monkey applications like C/C++ need a program entry point. It says this in the documentation under Monkey language reference->Programs and declarations. I suggest that you should have a read of the documentation as some of the posts only give you just snippets of code and not fully working examples.



monoloc(Posted 2014) [#4]
exists, otherwise do some 2d array?
for use with html5 and android?
or installing the c + + libraries and I can use it in any project
html5 and android.?
thought it would be something easier, to implement
some things my knowledge is very limited.
using arrays I could do many things in other languages
but it was so easy to use as what I wrote first. "in basic"


dawlane(Posted 2014) [#5]
Monkey is as write once; compile any where language. The Monkey compiler trans, translates monkey code into a target compatible source file that is either compiled by a back end compiler or run by a back end runtime interpreter. Which method that gets used depends on the target.
For example
Desktops will use C/C++ (back end is a C/C++ compiler GCC, Visual Studio, XCode)
HTML5 will use JavaScript (back end is a runtime interpreter used by the web browser)
Android/Ouya will use Java (back end is a runtime interpreter with options to use a back end compiler to native CPU architecture)
iOS will use a mixture of Objective-C/C/C++ (back end XCode)

You cannot install c++ libraries and just use them on any target. If a c++ library has been ported over to a target; then it's up to you to write the glue code to make it work with Monkey.

Monkey is an intermediate object orientated programming language and is more like C/C++/C#/Java and like these languages, multidimensional arrays have to faked.


ziggy(Posted 2014) [#6]
@dawlane: Just some considerations about your post, as I honestly think there are some mistakes there, and maybe it's interesting to someone to get what I think is a bit more detailed information.
HTML5: In most browsers, JavaScript is compiled in RAM (instead of being interpreted) by using a JIT, so its speed can match any compiled program. If it does not *sometimes* is due to the need of constant late-binding required by JavaScript not being type safe. But JavaScript on Chrome (as an example) is extremely fast in execution time.

Java: Android or OUYA do not directly use Java, they're using the Dalvik VM which natively compiles code. It's a VM that resembles the Java VM and it's very easy to convert bytecode from Java BC to Dalvik. Also, when the backend is Sun's Java or OpenJDK, the program is not interpreted. In this case, It's compiled just in time (that is, just before the program launches) and then it is run natively, like any typical C++ application. The idea that Java is interpreted comes from its very first incarnations from 1990, but this is not true since decades.

In fact, I think none of the Monkey targets are interpreted... ? Even AS 3.0 is compiled (except for the class constructors if I don't recall wrong,).


dawlane(Posted 2014) [#7]
@ziggy: I was typing the previous post on an iPad which is not the best device for doing detailed explanations first thing in the morning after a rough nights sleep. But you are right with HTML and Java being compiled. But as I understand it, Java/Dalvik VM does the interpretation of byte-code and will either use Just-In-Time compilation or interpret the byte-code. I did read somewhere that there was an experimental runtime for Android that did Ahead-Of-Time compilation (pre-compling the byte-code to native during installation).