Today 17th of April 2018
Day 3801
In the name of the most beautiful eyes.
This is 2nd part of my tutorial on Erepublik automation coding. in previous article, we went through basics of javascript and as promised in this article we will cover:
• Conditional Sentences
• Conditional Sentence Code in Erepublik
This tutorial is going to be a little hard but read it carefully so you will be able to understand how it works properly.
Conditionals
First of all we need to know about two concepts in programming:
True and False
in conditions and loops true and false concepts play the base role.
Operands
==
== represents "is it equal?"
so 3 == 3 means is 3 equal to 3?
so the result of 3 == 3 is "true".
The same happens when we use math:
1 + 2 == 3 is true again.
1 + 2 == 4 is false.
remember variables we talked about in previous article? let us check it with variables too.
var energy = 600;
result = energy == 600
so it would change to:
result = true
< or > and =
it's the same with < and > operands:
energy < 500 : is energy less than 500?
energy > 200 : is energy more than 200?
so what about less than or equal
and more than or equal?
we can use = for this purpose.
example:
energy = 300 : is energy more than or equal 300?
!=
!= means it is not equal?
so 2 != 3: 2 is not equal to 3? is true.
How to make it work?
well remember the shoot function we talked about in the first article?
now we are gonna define your current energy and see how does if function work?
Here is a little bit of code using one of erepublik object. and object is like a box. When you open that box there might be a lot of variables inside it.
Don't get into what object is but for now we are going to use one.
if ( energy < 600 ) {
if ( erepublik.citizen.energyFromFoodRemaining > 50 ){
}
}
The code in both {} works only if the question in () is right.
this question is called condition in programming.
There are two conditions here:
2- erepublik.citizen.energyFromFoodRemaining > 50 : is remaining food recovery more than 50?
if both conditions are true then your code will automaticaly eat food.
Here is the complete syntax of using conditionals:
if ( condition ){
}
else if ( condition ){
}
else {
}
We use else if to check for another condition if the first one fails. and if none of them true javascript will go through else block and do the code in else block.
For more you can watch this youtube if you want to know more. except switch statements which are not nessesary for your need.
I will promise to cover loop conditions in the next tutorial and also I will translate it to Farsi as soon as I have time, also if anyone wants to translate this articles to other language direct message me in Erepublik.
Yet I will try to make PDF version of this so the code segments will look alive and with style.
Thank you for spending your time reading my article, Endorsments are appericiated and please vote and subscribe for more, and please leave comments if any question and also my mission.
Thank you again.
Comments
Please Shout:
🏵 Learn Code: If Erepublik Else Nothing 🏵
erepublik.com/en/article/2669514
Thats so cool and useful
Tnx
تازه اولین نفرم بودم شیرینیم فراموش نشه
Successfully transferred 50 item(s) to 11alexlee11.
Thanks and b successfull
آفا عالی ، امشب میام ترجمه میکنم اول برات میفرستم عزیز بعد تایید کردی چاپ میکنم اگه اکی بودی
واقغا زحمت کشیدی 100 سی سی اندورس کفایت نمیده 😁
مرسی برای ساپورت
دمت گرم عالی بود
قربان شما
ممنون مرسی رفیق
Great. 🙂
واقعا فوق العادس
fantastic!!!
👌👌👌
👌👌👌
end if;
? >
الان دگه مشکلی نیست ارور نمی ده 😛
#ENDIF برای برنامه نویسیه سی هست
😑
اون مال پی اچ پی بودش خب
پس بیام جاوا اسکریپت یاد بگیرم از مقالاتت 😛 😃
Voted
ty
cool
The title bugs the crap out of me. 😋 It's a syntax horror. Or error, whatever. 😁
You can swap the title code
Translated in code, it does nothing. If erepublik, nothing. Else, nothing. See my point? You're missing the "true" block.
Haha got youe point 😁))))
Well, I subscribed to your newspaper and I look forward to reading your next articles. 🙂 It's a great idea, and I hope eRep will allow it to continue. Learning by experimenting in the games we play are a great way to gather knowledge while having fun. 🙂
Im greatful hearing it... also Erep will allow it as long as it stays in game topics.
Are you sure? Cause I'm pretty sure that scripts are officially forbidden..
Still I really like your articles and I plan on saving them, just in case if they get taken down.
The newspaper is allowed to talk about... you are not allowed to use script... but there is thoriaticaly no mechanism to detect script usage 😁
Ah, of course. I don't know how I've missed that.. xD
Are you sure there isn't? I'm pretty sure there are many many ways to detect scripts..
However devs here are the laziest I've ever seen, so that's nice. 😛
V.
Voted! 🙂
Please write comment back here:
Junior Journalist 2/3
erepublik.com/en/article/2669509
Thank you 🙂
I have done it long time ago
💜💜💜violet💜💜💜
بسیار عالیه
[removed]
[removed]
Awesome
آموزشهای ابتدایی اکثرا بلدن
بهتره بریم سراغ بخشهای پیچیده
دارم آماده میکنم بخش آموزش نوشتن اکستنشن رو
ایول
وات؟
حس خوندن و ترجمه ندارم ببینم راجب چیه و چی میگی
اگه حال داشتی خلاصشو بگو
vote