var start = Random(2)+1;
if(start==1) var xb=82, yb=50;
if(start==2) var xb=244, yb=50;
Schedule(nil,Format("CreateObject(MyNameObject, xb, yb, NO_OWNER)"), 7,0);
//Schedule(nil,"CreateObject(MyNameObject, xb, yb, NO_OWNER)", 7,0); also tried this
It doesn't work. How to fix it ?
if(start==1) var xb=82, yb=50;
if(start==2) var xb=244, yb=50;
Schedule(nil,Format("CreateObject(MyNameObject, xb, yb, NO_OWNER)"), 7,0);
//Schedule(nil,"CreateObject(MyNameObject, xb, yb, NO_OWNER)", 7,0); also tried this
It doesn't work. How to fix it ?
You cannot (at least should not) declare variables inside a condition and use them outside, see this example:
If you want to do it like that, you will have to do:
What did the error say, btw? :)
if(false) var x = 1;
Log("%d", x);
x
will never be declared here, what would happen?If you want to do it like that, you will have to do:
var x, y;
if(foo) { x = 82; y = 50; }
..
What did the error say, btw? :)
I did not have error.
It don't be create. =.=
var start = Random(2)+1;
if(start==1) var xb=82, yb=50;
if(start==2) var xb=244, yb=50;
CreateObject(Ball, xb, yb, NO_OWNER)
/\
it work, but i want to create it after time.
It don't be create. =.=
var start = Random(2)+1;
if(start==1) var xb=82, yb=50;
if(start==2) var xb=244, yb=50;
CreateObject(Ball, xb, yb, NO_OWNER)
/\
it work, but i want to create it after time.
Ah, so you didn't understand that line in #openclonk. I'll elaborate:
If you Schedule something, all the information available at the time of command execution is the object context to execute it in (nil in your case) and the command string. That string contains, for example, "xb". xb however, can only be understood by C4Script and turned from the name into a value at the time of the function execution. Which means: You will have to make the string contain the actual value, not the name of the variable. (Side note: Schedule may not stay that way forever, that's a more advanced topic though.)
How you do that: Format.
For example:
In your case that would be:
If you Schedule something, all the information available at the time of command execution is the object context to execute it in (nil in your case) and the command string. That string contains, for example, "xb". xb however, can only be understood by C4Script and turned from the name into a value at the time of the function execution. Which means: You will have to make the string contain the actual value, not the name of the variable. (Side note: Schedule may not stay that way forever, that's a more advanced topic though.)
How you do that: Format.
For example:
Format("SetWealth(0,%d)", w)
evaluates to "SetWealth(0,100)"
, given w was 100.In your case that would be:
Schedule(nil,Format("CreateObject(%i, %d, %d, NO_OWNER)", MyNameObject, xb, yb), 7,0);
Ah, I get what you mean now.
The stuff in Schedule does not know anything about the other variables. You will have to put it directly into the string:
For example:
The stuff in Schedule does not know anything about the other variables. You will have to put it directly into the string:
For example:
var x = 300; Schedule("Explode(x)",..) <- doesnt work
Schedule("Explode(300)", ..); <- works
Schedule(Format("Explode(%d)", x), ..); <- works
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill