Question to Codea written in Codea

Thanks :slight_smile:
I donā€™t think, that Iā€™m able to write an own module, but my game donā€™t need gravity.

loadstring() doesnā€™t work!

@aurumcoder2624 - that is plainly not true, it is widely used.

Please donā€™t make sweeping statements without providing proof - rather post the specific details of what is not working. It is highly likely you are not using it correctly.

Code I am using:

a = 1
loadstring("print(a)")

@aurumcoder2624 loadstring("print(a)")()

Thanks.

@aurumcoder - you are using it wrong.

From the documentation (try reading it when something doesnā€™t work)
ā€œParses the string and returns the compiled chunk as a function. Does not execute it.ā€

Got that? ā€œDoes not execute itā€. So you have to assign it to a variable and then run it. This is how you use it

a=1
f=loadstring("print(a)")
f()

Well?

Oh. Thanks

BTW @JakAttak ur code didnā€™t work I got:

error: [string "-- Loadstring..."]:7: attempt to call a nil value

@aurumcoder2624, sorry I fixed it didnā€™t mean to have the function() part.

Hello,
I have a question.
I want to make something like LoveCodea to port my game to a lua framework wich supports Android. My problem is, that I donā€™t know how to do something like this.
It would be great if someone could help me.

i dont know either, but i wish you good luck. Are you aware of the huge effort it would be? It is probavly easier to program your game directly in android langage (javascript + html5?).

I am old school I suppose. Codea is a prototyping language. Use it to quickly test and design games on the go. When you are ready to go professional you will need to use the native language for your game. Xcode for macs for example or I think it is java for android. When you try to convert three systems over, Mac, PC, and then android, there will be so many bugs and problems youā€™ll waste a lot of time.

The codea runtime works because it is basically the codea app without the editor. Being written in obj-C means it can just use the runtime made by till for codea as everything already works. Sorry that probably made no sense.

I donā€™t want to code in Java. In my opinion itā€™s too much work.
I coding in lua or Python is much easier.
There are frameworks wich are using lua and can export to Android and iOS, but I like Codea more. Itā€™s more fun to code on a tablet.
And it is possible to write a runtime.
There are LoveCodea and the Moai runtime

@Ignatz, and @JakAttak, I really appreciate ur help, but why is loadstring any different from function? Parses the code means that it saves into a global var, right?

Furthermore, the synthax is not so different, either.

loadstring("a=1")()

And

f = loadstring("Hello")
f()

Doesnā€™t seem so different against

(function()a=1 end)()

. To top it all off, loadstring apparently parses the code and pastes it into a local var, which probably takes up more space than

function

. The only thing different about these two things is that loadstring created functions don't take parameters, which... 1. Rejects the possibility that it may be a python copy of lambda, and 2. In my eyes, functions that don't take parameters are pretty much useless, except for setup and draw. 

My point is, what is the point of loadstring? Correct me if I'm wrong, but what, just what are the point of loadstrings?

Others will tell you why loadstring can be useful, but it should always be a last resort, and usually there are better alternatives.

Lua doesnā€™t need a python copy of lambda because you can already define anonymous functions very easily.

Variables donā€™t store function code, only the address where the code can be found, so using loadstring makes no difference to stack space, afaik.

Oh, thanks, @Ignatz!

@aurumcoder - bumping posts after 12 minutes and saying ā€œWell?ā€ or ā€œHuh?ā€ is plain rude and/or immature.

First, people on the forum donā€™t have any obligation to respond to your posts. Many of them have jobs and lives to lead.

Second, we come from all around the world, mostly Europe, and right now, Europe is sleeping.

So please stop being petulant and learn to be patient and less aggressive. Your question is not necessarily the most important thing on this forum.

Europe? And please stop expecting me to be like @Dave1707 or @Coder or @JakAttak, Iā€™m still relatively new here and Iā€™m still learning the ropes! Do u expect me to know rocket science as soon as Iā€™m in the field?

Ok, this might be an issue for ā€œsimple mannersā€, but Iā€™m still new to the concept of ā€œbumpingā€ in Codea? Again, Iā€™m still kind of a noob in Codea, so donā€™t push me!