T
T
Tera Incognita2020-12-04 20:30:38
Game development
Tera Incognita, 2020-12-04 20:30:38

How to add two numbers in Lua in Coregames?

The simple addition operation does not work.
I write the code correctly:

print=UI.PrintToScreen
b=1;
c=1;
a =  b + c ;
 print (a)


And like this:
print=UI.PrintToScreen
 
 print (1+2)


Does not work.
The program is coregames.
Failure and all ...
Who knows how easy it is to add two numbers?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dollar, 2020-12-05
@Lunali

Not personally familiar with the coregames program (although thanks for clarifying).
However, offhand, I can assume that the UI.PrintToScreen function accepts only one line and does not accept any numbers. Therefore, you need to convert the number to a string:

print=UI.PrintToScreen
b=1;
c=1;
a =  b + c ;
print (tostring(a))

The same effect can be achieved with a string concatenation operation due to automatic type casting in Lua when using this operation: Well, if you take the question seriously, then here:
print("The result = " .. a)
crash and all...

You are missing important information. The nature of the failure says a lot about the problem. It's sad if the app just crashes or freezes. But often, when an error occurs, it displays the details of the error. For example, it can be something like a message: "line 5 - the number and / or types of arguments for the function are incorrect." After this information, it is very easy to guess what the matter is. Even if you yourself did not understand the meaning of the message, the question should have indicated all the details of the failure , how it occurs and what it outputs. This is your advice for the future.

V
Vasily Bannikov, 2020-12-04
@vabka

Have you tried writing UI.PrintToScreen(tostring(1+2))
?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question